The return type is void and the input parameter is int. I had to generate random numbers from 1 to 100 using Math.random() and using a while loop only and continually print out the first input parameter number with how many even numbers there were.
Ex: prtEven(5) will print out the following even integers: 56 8 12 76 44
My code prints out numbers put it isnt random, it doesnt print out the input parameter number first, and for some reason it does not output the correct number of even numbers. Could someone pls help me. While Loop only
public class MeLoop
{
public int a, b;
public String str;
public void prtEven(int d){
int count = 0;
int number = d;
int sumEven = random % 2;
while(count <= 100){
int random = (int)(Math.random()*100);
count++;
System.out.print(count + " ");
}
if(sumEven == 0){
System.out.println("\tThere are: " + sumEven + " even numbers");
}
}
}
Aucun commentaire:
Enregistrer un commentaire