import java.util.Random;
public class WhileLoop {
public static void main(String[] args) {
Random random = new Random();
int a = 1000;
int b = 0;
int c = random.nextInt(10);
int d = random.nextInt(50);
int sum1;
int sum2;
int sum3;
int sum4;
System.out.println(c);
System.out.println(d);
while(sum4>sum2) {
sum1 = a + c;
sum2 = sum1 + c;
sum2++;
System.out.println(sum2);
sum3 = b + d;
sum4 = sum3 + d;
sum4++;
System.out.println(sum4);
}
}
}
I have trouble understanding
how to add a random number
to a number 0-10
and to b the numbers 0-50
until the condition is met
a = 1000;
b = 0;
the condition is b> aHow to add random numbers to some basic while b > a ?
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Lisa L
5 June 2022, 20:22
I do not understand what exactly you try to achieve but your code won't compile cause you're using variables you do not have initialized. In the condition in line 18 sum2 and sum4 are declared but not initialized. You didn't assign them values and hence they are in an undifined state. Assign them values and you can at least test your code. If you want to create new random values inside the while loop, then you need to use nextInt inside that loop like:
0
Karol Grzeszczak
5 June 2022, 20:51
just what you wrote I didn't know how to add value
0