1
所以我在java中有這個簡單的代碼。但是,當我試圖「再次使用該程序」寫在代碼中,它總是跳過第一項是輸入名稱。我該如何解決?迭代後跳過一行
下面的代碼:
import java.util.Scanner;
public class Try{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int salary;
String name, perform;
int choice = 1;
do{
System.out.println("Enter your name:");
name=sc.nextLine();
System.out.println("Enter your performance:");
perform=sc.nextLine();
System.out.println("Enter your salary:");
salary=sc.nextInt();
System.out.println("Name: "+name);
System.out.println("Performance: " + perform);
System.out.println("Salary:" + salary);
System.out.println("Do you want to use the program again?\n[1]Yes\n[2]No");
choice=sc.nextInt();
}while (choice < 2);
}
}