So basically I'm stuck at the do-while statement. Should I use a do while? or a for loop?
This program is supposed to test my ability to use loops.
/*Create an application that reads an integer value and prints the sum of all even integers between 2
* and the input value, inclusive. Print an error message if the input value is less than 2.
*/
import java.util.Random;
public class Project3
{
public static void main (String[]args)
{
int critical,test,count = 2;
Random rand = new Random ();
critical = rand.nextInt(21);
test = critical % 2;
System.out.println("The random number is: " + critical);
if (test == 1)
System.out.println("Not an even number. Thank you, come again!");
else
{
do
{
System.out.println(count + count);
count += 2;
}
while (count != critical);
}
}
}