Sum of numbers
First off I am new to java and I am doing some self-study.
I have wrote a program that asks the user to enter two numbers and displays the sum of these two numbers, it then gives the user a opportunity to have another go or to quit the program:
public class Numbers
public static void main(String args)
int num1, num2;
System.out.print("Enter a number: ");
num1 = EasyIn.getInt();
System.out.print("Enter another number: ");
num2 = EasyIn.getInt();
System.out.println("The sum of the two numbers is "
+ (num1 + num2));
System.out.print ("Do you want another go (y/n): ");
choice = EasyIn.getChar();
}while(choice == 'y');
I have a couple of questions:
• How could I adapt the above program so the user would be given another go irrespective of whether or not an upper case or lower case ‘y’ is entered?
• How could I make it so instead of displaying the sum of the numbers, it asks the user to enter the sum. Then if it is correct a congratulations message is displayed and if incorrect then the correct answer is displayed.
Any feedback would be much appreciated.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center