title: How to read multiple inputs on same line in Java?
body: <p>So I'm trying to read all the input from one line, using scanner, then take the values and find the second largest. I would use an array <strong>BUT</strong> I am not allowed. You are supposed to enter 10 integers, hit enter and evaluate them.</p>
  
  <p>Something like this:</p>
  
  <pre><code>10 20 30 40 50 60 70 80 90 100 ENTER
  
  Second highest number is: 90
  </code></pre>
  
  <p>I can't manage to solve it at all. It should be easy but I have no idea.</p>
  
  <pre><code>public class SecondLargest {
  
  public static void main(String[] args) {
      {
          int largest = 0;
          int secondLargest = 0;
          Scanner sc = new Scanner(System.in);
          System.out.print("Enter integers: ");
          int numbers = sc.nextInt();
          largest = numbers;
  
          while (sc.hasNextInt()) {
              if (numbers &gt; largest) {
                  secondLargest = largest;
                  largest = numbers;
              } else if (numbers &gt; secondLargest) {
                  secondLargest = numbers;
              }
          }
          System.out.println("Second largest number is: " + secondLargest);
          sc.close();
  
      }
  }
  </code></pre>