- 1
Why the code below not showing any output... Anyone can help me plz...
enum color { RED, BLUE, GREEN; } class PrintColor { public static void main(String[] args) { Color color = Color.RED; switch (color) { case BLUE : System.out.println ("1"); break; case GREEN : System.out.println ("2"); break; default: System.out.println ("0"); break; } } }
10 Answers
+ 2
0
+ 1
Thnks all for the help
0
In first line, write color with capital C
0
Try this -
enum Color
{
RED, BLUE, GREEN;
}
public class PrintColor
{
public static void main(String[] args) {
Color color = Color.RED;
switch (color) {
case BLUE :
System.out.println ("1");
break;
case GREEN :
System.out.println ("2");
break;
default:
System.out.println ("0");
break;
}
}
}
0
Answer = 0
0
0
0
0
0
0
0
o is the aswer using
0
import java.util.Scanner;
public class color {
public static void main(String[] args) {
String color="";
Scanner in = new Scanner(System.in);
color=in.next();
switch(color) {
case "red":
System.out.println(1);
break;
case "green":
System.out.println(2);
break;
case "black":
System.out.println(3);
break;
default :
System.out.println("Nothing");
break;
}
}
}