user input
5
Required output (using while loop)
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Code:
while (temp1 <= a) {
while (temp2 <= a) {
temp = temp2 * temp1;
System.out.print(temp + " ");
temp2++;
}
temp1++;
System.out.println();
}
i am taking a as input and try to form that figure but i can't.. please help
Value of temp2 after inner while loop will be a+1. Since you not resetting it to 1 later you will not enter this inner loop again because condition while(temp2<=a) will not be fulfilled. To correct it set temp2 to 1 inside outer loop, before or after inner loop.
If I have to break down the problem into simple words,
There are n number of ways you can do it.
I guess using for loops would be the simplest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With