エラーメッセージでは"シンボルを見つけられません"と表記されます
僕は最終的にローカル変数"choice"を作成しこの問題を解決しましたが本来はどのようにこのエラーに対処するのかが知りたいのでご教授お願いします。
P.S.開発環境はNetBeans IDE 8.1 です
java
1public class Week7 { 2 3 private static int choice; 4 5 /** 6 * @param args the command line arguments 7 */ 8 public static void main(String[] args) 9 { 10 // Tally program 11 12 // Present the user with a menu 13 // to enter a number between 1-4 inclusive 14 // Whichever number gets entered, we keep 15 // a count (tally) of how many times 16 // they enter theat number 17 // Repeat this untill the user enters "5" 18 // to show the tally and then end the 19 // program 20 21 Scanner input = new Scanner(System.in); 22 int count1 = 0; 23 int count2 = 0; 24 int count3 = 0; 25 int count4 = 0; 26 int choce; 27 28 do 29 { 30 System.out.println("1) Record 1"); 31 System.out.println("2) Record 2"); 32 System.out.println("3) Record 3"); 33 System.out.println("4) Record 4"); 34 System.out.println("5) Show tally"); 35 System.out.print("\nEnter choice: "); 36 37 choice = input.nextInt(); 38 39 /* 40 if (choice == 1) 41 count1++; 42 else if (choice == 2) 43 count2++; 44 else if (choice == 3) 45 count3++; 46 else if (choice == 4) 47 count4++; 48 else 49 { 50 System.out.println(count1); 51 System.out.println(count2); 52 System.out.println(count3); 53 System.out.println(count4); 54 } 55 */ 56 // If I have one variable to test 57 // and am testing it with a fixed 58 // set of values, we can write 59 // the code using a switch 60 61 switch (choice) 62 { 63 case 1: 64 count1++; 65 break; 66 case 2: 67 count2++; 68 break; 69 case 3: 70 count3++; 71 break; 72 case 4: 73 count4++; 74 break; 75 default: 76 System.out.println(count1); 77 System.out.println(count2); 78 System.out.println(count3); 79 System.out.println(count4); 80 break; 81 } 82 } while (choice != 5); 83 } 84 85} 86
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/17 06:23