Results 1 to 3 of 3
- 07-24-2011, 09:01 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 1
- Rep Power
- 0
Application Switches demonstrates the use of the Switch
There is no prompt for input in this application...where do I put the prompt?
// Application Switches demonstrates the use of the Switch
// statement.
import java.util.Scanner;
public class Switches
{
public static void main(String[] args)
{
char code;
int answer;
int one;
int two;
String inputString;
boolean quit = false;
Scanner inLine = new Scanner(System.in);
do
{
inputString = inLine.nextLine();
code = inputString.charAt(0);
if (code != 'Q')
{
inputString = inputString.substring(1, inputString.length());
Scanner string = new Scanner(inputString);
one = string.nextInt();
two = string.nextInt();
switch (code)
{
case 'A' : answer = (one + two);
System.out.println(one + " + " + two
+ " is " + answer);
break;
case 'S' : answer = (one - two);
System.out.println(one + " - " + two
+ " is " + answer);
break;
case 'M' : answer = (one * two);
System.out.println(one + " * " + two
+ " is " + answer);
break;
case 'D' : answer = (one / two);
System.out.println(one + " / " + two
+ " is " + answer);
break;
}
}
else
quit = true;
} while (!quit);
}
}
- 07-24-2011, 09:05 PM #2
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
Java Code:do { System.out.println("enter the string"); inputString = inLine.nextLine(); code = inputString.charAt(0); if (code != 'Q') {
Java Code:Scanner string = new Scanner(inputString); System.out.println("enter "); one = string.nextInt(); System.out.println("enter "); two = string.nextInt(); switch (code)
Last edited by fakepics500; 07-24-2011 at 09:12 PM.
- 07-24-2011, 09:30 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Similar Threads
-
Using switches...
By besweeet in forum New To JavaReplies: 11Last Post: 03-04-2010, 05:48 PM -
help with switches
By spots of fire in forum New To JavaReplies: 1Last Post: 01-23-2010, 10:02 PM -
Demonstrates printing images
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 05:42 PM -
Demonstrates how to draw vertical text in SWT
By Java Tip in forum SWT TipsReplies: 0Last Post: 06-28-2008, 10:26 PM -
Help with switches
By Daniel in forum New To JavaReplies: 2Last Post: 07-04-2007, 09:37 AM
Bookmarks