QuestionAsk Questions?

View Answers

July 13, 2009 at 2:21 PM

Hi Friend,

Try the following code:

public class RandomNumberArray {

private static void showNumbers() {

int randomNumbers=0;

int min = -5;

int max = 45;

int counter=0;

String st="";

int sum=0;

int[] ranNum = new int[50];

for ( int i = 0; i < ranNum.length; i++) {

counter++;

ranNum[i] = (int)(Math.random() * (max - min + 1) ) + min;

randomNumbers=ranNum[i];

st=Integer.toString(randomNumbers);

sum+=ranNum[i];

if(counter==10){

st+="\n";

}

if(counter==20){

st+="\n";

}

if(counter==30){

st+="\n";

}

if(counter==40){

st+="\n";

}

System.out.print(st+" ");

}

int average=sum/50;

System.out.println("\n"+"Average of Numbers is: "+average);

}

public static void main(String[] args) {

showNumbers();

}

}

Thanks

Try the following code:

public class RandomNumberArray {

private static void showNumbers() {

int randomNumbers=0;

int min = -5;

int max = 45;

int counter=0;

String st="";

int sum=0;

int[] ranNum = new int[50];

for ( int i = 0; i < ranNum.length; i++) {

counter++;

ranNum[i] = (int)(Math.random() * (max - min + 1) ) + min;

randomNumbers=ranNum[i];

st=Integer.toString(randomNumbers);

sum+=ranNum[i];

if(counter==10){

st+="\n";

}

if(counter==20){

st+="\n";

}

if(counter==30){

st+="\n";

}

if(counter==40){

st+="\n";

}

System.out.print(st+" ");

}

int average=sum/50;

System.out.println("\n"+"Average of Numbers is: "+average);

}

public static void main(String[] args) {

showNumbers();

}

}

Thanks

Related Tutorials/Questions & Answers:

Advertisements