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程序。說「找不到符號 - 變量V」
你所有的選擇都是char,所以你需要把它寫成'case'V':'等等 – sakura
根據命名約定,類名應該以大寫字母開頭('color '應該是'Color')。 – Tiny