gpt4 book ai didi

java - 跳过 while 循环的第一行

转载 作者:行者123 更新时间:2023-12-01 13:18:53 35 4
gpt4 key购买 nike

ask=1;
while(ask==1)
{
System.out.println("What is your phrase?");
phrase=sc.nextLine();
System.out.println("What is your additive key?");
key=sc.nextInt();
String code=addit(phrase, key);
System.out.println(code);
System.out.println("Enter 1 to go again");
ask=sc.nextInt();
}

第一次通过循环后直接跳到询问我的附加 key 是什么,有人知道为什么吗?

最佳答案

因此,根据 @PakkuDon 的说法,这应该可以解决问题:

ask = 1;
while(ask == 1)
{
System.out.println("What is your phrase?");
phrase = sc.nextLine();
System.out.println("What is your additive key?");
key = sc.nextInt();
String code = addit(phrase, key);
System.out.println(code);
System.out.println("Enter 1 to go again");
ask = sc.nextInt();
String tmp = sc.nextLine();
}

关于java - 跳过 while 循环的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22214715/

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