Hello, im Ant. Forum looks really good. Im currently in the very early stages of learning Java, i have a few books and am doing online tutorials etc so looks like i will be using this place and searching the forums loads in the near future.
At the moment im trying doing small projects in a book i have but im stuck with Selection and loops. I have a small program here and im trying to get it so it only accepts even numbers in the range of 1 to 100 and capital and small "n" terminates the program. Can anyone please help me out?
Thank you!!
import java.util.*;
public class RepeatList
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int Number = 0, Sum = 0; //variables
char Choice;
//if (Number %2 ==0)
do
{
System.out.println("Enter the list of whole numbers, terminated by -999");
Number = sc.nextInt();
while( Number != -999)
{
Sum = Sum + Number;
Number = sc.nextInt(); //scanner class var
}
System.out.println("Sum is "+ Sum);
System.out.print("Do you want to repeat the ");
System.out.println(" Program ['Y' or 'N']");
Choice = sc.next().charAt(0);
} while( Choice != 'N'); //while choice is not equal to N
}
}