gpt4 book ai didi

java - 为什么 System.out.println 无法打印出字符串值(在我的特定情况下)?

转载 作者:行者123 更新时间:2023-11-29 05:08:48 25 4
gpt4 key购买 nike

<分区>

我的程序应该要求用户输入一些值,最终应该根据选择的菜单选项打印出这些值(在我的例子中是 3)。我已经使用 System.out.println("Your name: "+ name); 打印出用户输入的名字,但不幸的是它无法打印出名字。该行只是空着。为什么这样?我该如何修复它。

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int userChoose;
String name = null;
int accNum = 0;
double initiateAmount = 0;
double newAmm = 0;

double depOrWith = 0;
System.out.println("WELCOME TO OUR BANK!\n\n"
+ "...................\n"
+ "...................\n\n"
+ "Choose your optiin:\n"
+ "1. Create new account\n"
+ "2. Deposit/withdraw\n"
+ "3. View details\n"
+ "4. Deleting an account\n"//not used yet
+ "5. View all the accounts\n"//not used yet
+ "6. Quit\n\n");
System.out.println("*************\n"
+ "************");
while (true) {
userChoose = sc.nextInt();

if (userChoose == 1) {

System.out.println("Enter your full name:");

name = sc.nextLine();
sc.nextLine();

System.out.println("Choose an account number:");

accNum = sc.nextInt();

System.out.println("Enter an initiating amount:");

initiateAmount = sc.nextDouble();
System.out.println("\n-----------\n"
+ "------------");
} else if (userChoose == 2) {

System.out.println("Enter negative value to withdraw and positive to deposit");
depOrWith = sc.nextInt();
if (depOrWith < 0) {

initiateAmount = initiateAmount + depOrWith;
} else {

initiateAmount = initiateAmount + depOrWith;
}

System.out.println("\n-----------\n"
+ "------------");

} else if (userChoose == 3) {

System.out.println("Your name: " + name);
System.out.println("Your account number: " + accNum);
System.out.println("Your current balance: " + initiateAmount);
System.out.println("\n-----------\n"
+ "------------");
} else if (userChoose == 6) {

System.exit(0);

}

}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com