[問題] 函式還沒執行完程式就結束了
如題 在練習物件時遇到了這個問題
原本的程式碼是
public void FirstCall(){
System.out.print("輸入字串:");
Str = in.InputStr();
System.out.print("起始位置:");
Pos = in.InputPos();
System.out.print("新字串:");
NewString = in.InputNewString();
}
但是這樣打我只輸入了字串跟起始位置 程式就結束了
但如果改成
public void FirstCall(){
System.out.print("輸入字串:");
Str = in.InputStr();
System.out.print("新字串:");
NewString = in.InputNewString();
System.out.print("起始位置:");
Pos = in.InputPos();
}
或是
public void FirstCall() {
Scanner input= new Scanner(System.in);
System.out.print("輸入字串:");
Str = in.InputStr();
System.out.print("起始位置:");
Pos = in.InputPos();
System.out.print("新字串:");
NewString = input.nextLine();
}
這樣子就沒有問題了
想請問各位大大這是甚麼原因呢
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.120.249.99
※ 文章網址: https://www.ptt.cc/bbs/java/M.1477723247.A.8EC.html
→
10/29 16:26, , 1F
10/29 16:26, 1F
→
10/29 17:03, , 2F
10/29 17:03, 2F
→
10/29 17:08, , 3F
10/29 17:08, 3F
→
10/29 22:06, , 4F
10/29 22:06, 4F
→
10/29 22:07, , 5F
10/29 22:07, 5F
→
10/30 00:07, , 6F
10/30 00:07, 6F
→
10/30 10:18, , 7F
10/30 10:18, 7F
→
10/30 14:53, , 8F
10/30 14:53, 8F
java 近期熱門文章
PTT數位生活區 即時熱門文章