In this program I want to generate two random numbers, take the largest number divide it by four and then display "I like loops" that many times. For example if the largest number is 20 it will take 20 divided by 4 and then it would display "I like loops 5 times. When I run it it only displays the two random numbers. Here is my code:
public static void main(String[] args) {
Random RanNum= new Random();
int num = 1,num2 = 1,loop;
for(int i = 1; i<=2; i++){
num = 1+RanNum.nextInt(50);
num2 = 1+RanNum.nextInt(50);}
System.out.print ("The 2 random numbers are "
+ num + " and " + num2+" ");
if (num>=num2){
loop= num/4;
while(num<=loop){System.out.println("I like loops");}
}
else if(num2>=num){
loop= num2/4;
while(num2<=loop){System.out.println("I like loops");}
}
}
}
Aucun commentaire:
Enregistrer un commentaire