0
    System.out.println("Number of pages + Number of lost pages + Number of Readers");
    
    int n = s.nextInt();
    int m = s.nextInt();
    int q = s.nextInt();

I want to read input values all the values are going to be integer but I want to read it in a same line with changing it form Integer.

Gokul
  • 21
  • 2
  • one line? without a String? and how do you suppose to tell your application to read, if not for pressing enter? – Stultuske Nov 24 '20 at 11:59

1 Answers1

0

Assuming s is an instance of Scanner: Your code, as written, does exactly what you want.

scanners are created by default with a delimiter configured to be 'any whitespace'. nextInt() reads the next token (which are the things in between the delimiter, i.e. the whitespace), and returns it to you by parsing it into an integer.

Thus, your code as pasted works fine.

If it doesn't, stop setting up a delimiter, or reset it back to 'any whitespace' with e.g. scanner.reset(); or scanner.useDelimiter("\\s+");.

class Example {
  public static void main(String[] args) {
    var in = new Scanner(System.in);
    System.out.println("Enter something:");
    System.out.println(in.nextInt());
    System.out.println(in.nextInt());
    System.out.println(in.nextInt());
  }
}

works fine here.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72