-
Sum of numbers
Hi,
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;
char choice;
do
{
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks