import java.io.*;
public class Color {
public void main() throws IOException {
BufferedReader br;
br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your choice");
System.out.println("Enter V for Violet");
System.out.println("Enter I for Indigo");
System.out.println("Enter B for Blue");
System.out.println("Enter G for Green");
System.out.println("Enter Y for Yellow");
System.out.println("Enter O for Orange");
System.out.println("Enter R for Red");
char choice;
choice = (char) br.read();
switch (choice) {
case V:
System.out.println("The spectrum color is Violet");
break;
case I:
System.out.println("The spectrum color is Indigo");
break;
case B:
System.out.println("The spectrum color is Blue");
break;
case G:
System.out.println("The spectrum color is Green");
break;
case Y:
System.out.println("The spectrum color is Yellow");
break;
case O:
System.out.println("The spectrum color is Orange");
break;
case R:
System.out.println("The spectrum color is Red");
break;
default:
System.out.println("Wrong Input");
}
}
}
它说----> cannot find symbol - variable v
...当我试图用bluej编码时。我目前正在学习java编程,这是我的第一个基本java程序。
答案 0 :(得分:4)
你应该尝试将你的字母写成真正的字符:
case 'V':
System.out.println("The spectrum color is Violet");
break;
您现在正在做的是检查选项是否是变量V
,当然,它不存在。
答案 1 :(得分:1)
要在Java中使用字符文字,您需要使用单引号。此外,您可能希望接受大写和小写 v 。所以你可以这样做:
switch (Character.toUpperCase(choice))
{
case 'V':
等等
答案 2 :(得分:0)
你应该比较字符。试试case 'V'
。
答案 3 :(得分:-2)
检查区分大小写。 ' V' ' V' ...