April 19th, 2013, 02:40 AM
-
Loop question
Hi How would i do a loop where is the user inputs a number, say n, the number would need to be positive and then give the multiples of 2 before n.
eg user inputs 10
output=
2
4
6
8
10
?? thanks
April 19th, 2013, 06:16 AM
-
April 22nd, 2013, 12:13 AM
-
Originally Posted by mathkid182
Hi How would i do a loop where is the user inputs a number, say n, the number would need to be positive and then give the multiples of 2 before n.
eg user inputs 10
output=
2
4
6
8
10
?? thanks
Code:
int n = 10; //set this to whatever number you want
for (int i = 0; i <= n; i+=2)
{
System.out.println(i);
}