Total Pageviews

Monday, February 13, 2012

JAVA PROGRAM WITH RANDOM FUNCTION


import java.util.Scanner;
import java.util.Random;

public class TenRandomNumbers {

public static void main(String[] args) {
// TODO Auto-generated method stub
int[] Random;
Random = new int[10];
int count = 0;
double average = 0;
int Max = 0;
int Min = 100;
int sum = 0;
int number = 0;


for (count = 0; count < 10; count++){
number = 50 + (int)(Math.random()*50);
Random[count] = number;
System.out.println(Random[count]);
sum = sum + number;
average = sum/10;
while(Random[count]>Max)
Max=Random[count];
while(Random[count]<Min)
Min=Random[count];
}
System.out.println("The average is: " + average);
System.out.println("The highest number is " + Max);
System.out.println("The lowest number is " + Min);



}

}

No comments:

Post a Comment