首页 > 解决方案 > 我在解决这个 java 问题时遇到了麻烦。看看你能不能帮忙

问题描述

    Scanner input = new Scanner(System.in);

    String accounts[][] = new String[2][6];

    for (int i = 0; i < 2; i++) {

        System.out.print("\n\n\tClient Code : SGBK-ACC008" + (i+1) + "\n\n");

        for (int j = 0; j < 6; j++) {

            if (j == 0) {
                System.out.print("\n\tAccount Number : ");
            } else if (j == 1) {
                System.out.print("\n\tFull Name : ");
            } else if (j == 2) {
                System.out.print("\n\tID Number : ");
            } else if (j == 3) {
                System.out.print("\n\tAccount Type : ");
            } else if (j == 4) {
                System.out.print("\n\tInitial Amount : ");
            } else if (j == 5) {
                System.out.print("\n\tAccount State : ");
            } else {
                System.out.print("\n\tError!");
            }

            accounts[i][j] = input.nextLine();

        }
    }

    System.out.print("\n\tInput Full \n\n");

    for (int i = 0; i < 2; i++) {

        for (int j = 0; j < 6; j++) {

            System.out.print(accounts[i][j] + "  ");
        }

        System.out.println();
    }
}

}

所以上面的这些代码行实际上是有效的,但是当它们是我正在尝试制作的更大程序的一部分时,它们不会。我正在尝试编写一个银行应用程序,其中有关客户的信息存储在多维数组中。

    Scanner sc = new Scanner(System.in);
    int choice, reponse = 0;
    double operation;


    String stockCompte[][] = new String[2][6];

    System.out.print("\n\t********** WELCOME TO E-CORP **********\n\n");

    do {

        choice = 0;

        System.out.print("\n\t---MENU ---\n");

        System.out.print("\n\t\t 1 - Open an Account");
        System.out.print("\n\t\t 2 - Debit");
        System.out.print("\n\t\t 3 - Credit");
        System.out.print("\n\t\t 4 - Transfer");
        System.out.print("\n\t\t 5 - Close an Account");

        System.out.print("\n\n\tChoose an option : ");

        choice = sc.nextInt();

        switch (choice) {

        case 1:

            System.out.print("\n\t\tOpen an Account\n");

            for (int i = 0; i < 2; i++) {

                System.out.print("\n\tAutomatic Client Code : SGBK-ACC008" + (i + 1) + "\n");

                for (int j = 0; j < 6; j++) {

                    if (j == 0) {
                        System.out.println("\n\tCreeate an Account Number - (Format : 01) : ");
                    } else if (j == 1) {
                        System.out.println("\n\tFull Name - (Format : NOM Prenom) : ");
                    } else if (j == 2) {
                        System.out.print("\n\tID Number : ");
                    } else if (j == 3) {
                        System.out.print("\n\tAccount Type : ");
                    } else if (j == 4) {
                        System.out.print("\n\tInitial Amount : ");
                    } else if (j == 5) {
                        System.out.print("\n\tAccount State : ");
                    } else {
                        System.out.print("\n\tError!");
                    }

                    stockCompte[i][j] = sc.nextLine();
                }

            }

            System.out.print("\n\tInput Full!\n\n");

            for (int i = 0; i < 2; i++) {

                for (int j = 0; j < 6; j++) {

                    System.out.print(stockCompte[i][j] + "  ");
                }

                System.out.println();
            }

            break;

        case 2:

            System.out.print("\n\t\tDebit\n");

            break;

        case 3:

            System.out.print("\n\t\tCredit\n");

            break;

        case 4:

            System.out.print("\n\t\tTransfer\n");

            break;

        case 5:

            System.out.print("\n\t\tClose an Account\n");

            break;

        default:

            System.out.print("\n\tWrong Choice!");

            break;

        }

        do {

            System.out.print("\n\tContinue ? (1 - Continue / 2 - Stop) : ");
            reponse = sc.nextInt();

        } while (reponse != 1 && reponse != 2);

        System.out.print("\n\tSession Ended!");

    } while (reponse == 1);
}

}

在这种情况下,数组中的第一行输入是成功的,但不是第二行。它不采用数组第二行的第一个值。

标签: javafor-loopswitch-statement

解决方案


推荐阅读