dimanche 24 janvier 2016

Java: Sort lowest-to-highest

Need to identify the names of the youngest/ oldest of the following three, using "if" statements: I can successfully list students by running the code, but need to identify just the youngest and oldest of the three.

public class  app
   {
      public static void main(String args[])
   {
      student st1 = new student();
      st1.setFirstName("Fred");
      st1.setLastName("Fonz");
      st1.setAge(44);

      student st2 = new student();
      st2.setFirstName("John");
      st2.setLastName("Smith");
      st2.setAge(20);

      student st3 = new student();
      st3.setFirstName("Zack");
      st3.setLastName("Mills");
      st3.setAge(21);

      System.out.println("student one info = "+ st1.getFirstName()+ " "+  
       st1.getLastName()+ " "+    st1.getAge());
      System.out.println("student two info = "+ st2.getFirstName()+ " "+ 
       st2.getLastName()+ " "+    st2.getAge());
      System.out.println("student three info = "+ st3.getFirstName()+ " "+ 
       st3.getLastName()+ " "+    st3.getAge());
  }
}

Aucun commentaire:

Enregistrer un commentaire