2014-03-06 155 views
0
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(); 
} 

直接跳到問什麼我的添加鍵在循環中第一次後有人知道爲什麼?跳過while循環的第一行

回答

1

因此,基於什麼@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(); 
}