java string variable using .next() or .nextLine()

后端 未结 1 722
借酒劲吻你
借酒劲吻你 2020-11-30 13:27

the following is my sources code:

package functiontest;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOExce         


        
相关标签:
1条回答
  • 2020-11-30 14:07

    Your problem is that the line

    option = scan.nextInt();
    

    does not read the new line character after the integer. So that new line is finally read when you do nextLine(), later on.

    To fix this, you should add an extra

    scan.nextLine()
    

    after the call to nextInt(), then use

    cname = scan.nextLine();
    

    when you want to read the clerk's name.

    0 讨论(0)
提交回复
热议问题