QuestionAsk Questions?

View Answers

August 20, 2009 at 4:27 PM

Hi Friend,

Try the following code:

<%@page import="java.util.*"%>

<%

int sum=0;

Random random = new Random();

out.println("Numbers are:");

for (int i = 1; i <= 40; ++i){

int nums = random.nextInt(50);

sum+=nums;

out.println(nums+" ");

}

out.println("Sum of Numbers: "+sum);

out.println("Average of Numbers: "+sum/10);

%>

Thanks

Try the following code:

<%@page import="java.util.*"%>

<%

int sum=0;

Random random = new Random();

out.println("Numbers are:");

for (int i = 1; i <= 40; ++i){

int nums = random.nextInt(50);

sum+=nums;

out.println(nums+" ");

}

out.println("Sum of Numbers: "+sum);

out.println("Average of Numbers: "+sum/10);

%>

Thanks

August 20, 2009 at 4:32 PM

Hi Friend,

Do one change in the provided code.As we have to calculate the average of 40 numbers so make change in the following line:

out.println("Average of Numbers: "+sum/40);

Thanks

Do one change in the provided code.As we have to calculate the average of 40 numbers so make change in the following line:

out.println("Average of Numbers: "+sum/40);

Thanks

August 20, 2009 at 4:33 PM

Hi Friend,

Do one change in the provided code.As we have to calculate the average of 40 numbers so make change in the following line:

out.println("Average of Numbers: "+sum/40);

Thanks

Do one change in the provided code.As we have to calculate the average of 40 numbers so make change in the following line:

out.println("Average of Numbers: "+sum/40);

Thanks

Related Tutorials/Questions & Answers: