このコードは、NetBeans 7.3 を使用して作成しました。これは単純な ATM プログラムの説明です。私の問題は、メニュー オプションを 2 回しか表示できないことです。2回目に繰り返すと、スイッチを切り替えることができません。この問題を解決するにはどうすればよいですか??
これは私のコードです:
public static void main() {
System.out.println(" ****************************************************" );
System.out.println(" * Can you please choose which one of the following *" );
System.out.println(" * services you want the program to perform by *" );
System.out.println(" * typing down the number of the option below: *" );
System.out.println(" * *" );
System.out.println(" * 1. Test credit card number. *" );
System.out.println(" * 2. Exit. *" );
System.out.println(" ****************************************************" );
int choice;
System.out.print("your choice is: ");
choice = console.nextInt();
//while (choice == 1 || choice != 2)
if (choice == 2) {
System.out.println(" *** Please visit us again. ***");
System.exit(0);
}
}
public static void main(String[] args) {
int choice;
System.out.println(" *****************************************************" );
System.out.println(" * Welcome to the credit card number test program *" );
System.out.println(" * *" );
System.out.println(" * First we would like to thank you for choosing *" );
System.out.println(" * our program and we hope you will find it useful *" );
System.out.println(" * *" );
System.out.println(" * We guarantee you that you will receive the best *" );
System.out.println(" * services in the world. *" );
System.out.println(" *****************************************************" );
System.out.print("your choice is: ");
choice = console.nextInt();
switch (choice) {
case 1:
int[][] credit_number = new int [3][16];
int row;
int col;
int sum;
String statue;
System.out.println("Please enter 16 number for a credit card: " );
row = 0;
{
for (col = 0; col < credit_number[row].length; col++)
credit_number[row][col] = console.nextInt();
}
while (choice == 1 || choice != 2)
main();
System.out.println();
break;
case 2:
System.out.println(" *** Please visit us again. ***");
System.exit(0);
default: {
System.out.println("Warning: Please make sure to choose an available option from the menu.");
main();
}
}
}}