import java.util.Scanner;
public class SwitchSample
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print ("Enter Size: ");
int size = scan.nextInt();
if (size > 59)
System.out.println("Big");
else
if (size > 29)
System.out.println("Average");
else
System.out.println("Small");
}
}
into a switch statement. This is what I have so far:
import java.util.Scanner;
public class SwitchSample
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print ("Enter Size: ");
int size = scan.nextInt();
switch (size)
{
case 1: System.out.println ("Small");
break;
case 0: System.out.println ("Average");
break;
default: System.out.println ("Big");
break;
}
}
}
I want the switch statement to do produce the same output as the if-statement. I'm not sure what I'm doing wrong with the code segment for the switch statement.
For example...
<output>
Enter size: 28
Small
This post has been edited by paadsp: 12 October 2010 - 11:20 PM

New Topic/Question
Reply




MultiQuote





|