title: How do you get the name of the oldest person using split strings and array in Java
body: <p>I've been staring at this problem for too long.. This is an exercise from <a href="https://java-programming.mooc.fi/part-3/4-using-strings" rel="nofollow noreferrer">https://java-programming.mooc.fi/part-3/4-using-strings</a> and I have to get the name of the oldest person through splitting the strings and finding the name with the oldest age.</p>
  
  <pre><code>&gt; Sample Input: Johnny, 5
  &gt;               Rose, 19
  &gt;               Sam, 10
  </code></pre>
  
  <p>Desired Output: Rose</p>
  
  <p>Any help would genuinely be appreciated. Thanks!</p>
  
  <pre><code>import java.util.Scanner;
  
  public class NameOfTheOldest {
  
      public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
  
          String name = "";
  
          while (true) {
  
              String input = scanner.nextLine();
  
              if (input.equals("")) {
  
                  break;
  
              }
  
              String[] pieces = input.split(",");
  
              int age = Integer.valueOf(pieces[1]);
  
              int oldest = 0;
  
              if (age &gt; oldest) {
  
                  name = pieces[0];
  
                  oldest = age;
  
              }
          }
  
          System.out.println("Name of the oldest: " + name);
      }
  }
  </code></pre>