Posted by Jean on Thursday, March 27, 2008 at 10:43am.
Java Programming Question:
basically want to keep the user in a loop that displays the menu and requests a user choice again and again until the user enters choice option 0 and exits the program.
When Option 1 is chosen, I want to ask the user, "How many numbers to add?" After they put in that number, I want to ask them, "Please enter the numbers one by one." like this
56
789
4
8999
231
Then, the program will display the result by saying, "The sum is:...."
Finally the menu should be displayed again to choose from.
If Option 2 is selected:
- the user will NOT be asked how many numbers are to be multiplied. Instead, the program will accept numbers until the user enters the numer "1" which will signal the end of the number series. So the dialogue should look like this:
Please enter the numbers:
56
43
2
99
767
1
"The product is: ___"
then the menu will be displayed again and the use prompted for a choice.
This is what I have so far...
import java.io.*;
public class p2
{
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );
public static void main ( String [] args ) throws IOException
{
System.out.println( "0-Exit" );
System.out.println( "1-Compute the sum of some numbers" );
System.out.println( "2-Compute the product of some numbers" );
String inputString = stdin.readLine();
int input = Integer.parseInt(inputString);
switch(input)
{
case 0:
break;
case 1:
break;
case 2:
break;
default:
System.out.println( "Invalid Selection" );
break;
}
System.out.println( "Bye Bye" );
}
}
No one has answered this question yet.
Answer this Question
Related Questions
Programming in c++ - Write a program in c++ that inputs a number [1-12] from the...
Computer programming - Sorting is a common operation used in programming. ...
programming - Using Raptor, create a condition loop that will ask the user for ...
programming - creat a logic for a program that continuously prompts the user for...
computer programming - : Create a program like KBC game show where program ask ...
Computer Science (MATLAB) - I had a test in my computer science course in which ...
Computer Science (MATLAB) - I had a test in my computer science course in which ...
Computing - Write a program that displays the following menu: 1 = Square 2 = ...
computer science - You are required to use the Account class to simulate an ATM ...
programming - write a program that asks the user to enter an objects mass, and ...
For Further Reading