title: User Input Java to a list and comprehension
body: <p>How do I prompt user to input numbers? I want to calculate percentage, so I want user to keep inputing integer. if the user press enter without entering anything then thats where the calculation starts</p>
  
  <p>this is the example output</p>
  
  <pre><code>Input Integer:
  
  2
  17
  1
  3
  
  The numbers and percentage:
     2      8.7%
    17     73.9%
     1      4.3%
     3     13.0%
    23    100.0%
  </code></pre>
  
  <p>After the user finish inputting the numbers, I want to sum them and calculate the proportion of each number compared to the sum.</p>
  
  <p>This is what I have done </p>
  
  <pre><code>package basic.functions;
  import java.util.*;
  import java.text.DecimalFormat;
  
  public class Percent {
      public static void main(String[] args) {
          Scanner reader = new Scanner(System.in);
          reader.useDelimiter(System.getProperty("line.separator"));
          List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
          System.out.println("Enter Integer: ");
  
          do {
              try {
                  int n = reader.nextInt();
                  list.add(Integer.valueOf(n));
              } catch (InputMismatchException exception) {
                  System.out.println("Not an integer, please try again");
              }
          }
  
          //When user press enter empty
          while (reader.hasNextInt());
          reader.close();
  
          //SUM all the integer elements in the list
          int sum = 0;
          for (int x : list)
              sum += x;
  
          //calculate the percentage of each integer that was entered as proportion of the sum
          //for all elements in the list, divide by the SUM then time 100 to get the percentage
  
  
          System.out.println("The numbers and percentage:");
  
          if (sum == 0) {
              System.out.println("Division by 0 not possible");
          }
          else {
  
              for (int x : list) {
  
                  System.out.println(x + "               " + ((x * 100 / sum) + "%"));
              }
  
              System.out.println(sum + "               " + ((sum * 100) / sum) + "%");
  
  
          }
      }
  }
  </code></pre>