How to read strings from a Scanner in a Java console application?

后端 未结 4 595
萌比男神i
萌比男神i 2020-12-01 18:46
import java.util.Scanner;
class MyClass
{
    public static void main(String args[])
    {
        Scanner scanner = new Scanner(System.in);
        int employeeId,          


        
4条回答
  •  再見小時候
    2020-12-01 19:17

    What you can do is use delimeter as new line. Till you press enter key you will be able to read it as string.

    Scanner sc = new Scanner(System.in);
    sc.useDelimiter(System.getProperty("line.separator"));
    

    Hope this helps.

提交回复
热议问题