java - 我在解决这个 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);
}
}
在这种情况下,数组中的第一行输入是成功的,但不是第二行。它不采用数组第二行的第一个值。
解决方案
推荐阅读
- java - 我试着用谷歌搜索这个。双链表问题。已编辑(2)
- r - 返回具有最少矩阵数的列表
- django - 在使用 ModelSerializer 创建之前编辑字段
- facebook - 如何从 Facebook 评论中读取标记的用户 - Facebook API
- java - 文件未复制到路径中
- javascript - 使用 addEventListener 将数字传递给外部 js 文件
- css - 将 ::-webkit-scrollbar 应用于除一个之外的所有元素
- php - 加载 gRPC 二进制模块失败(gRPC php 教程)
- python - 如何将序列提供给 TensorFlow Keras 模型?
- excel - 如何根据列中的条件将行从一张表复制到另一张表 - 仅粘贴值和格式(而不是公式)?