title: Determine largest/smallest number
body: <p>im trying to code a java program that gets 5 numbers from user and determines which is the largest and which is the smallest, i got a problem with the logic , i cant quiet figure how to compare all 5 input numbers with one another and determine the largest and smallest :</p>
  
  <pre><code>import java.util.Scanner;
      public class determine {
  
      public static void main (String [] args) {
  
          Scanner scan=new Scanner(System.in);
  
  
              System.out.println("enter 5 numbers : ");
              for(int i=1; i&lt;=5; i++){
              int num=scan.nextInt();
  
              if (num is bigger than the rest)
  
                  System.out.println(num+" is the largest");
  
                  if (num is smaller than rest )
  
                      System.out.println(num+" is the smallest");
  
  
  
          }
  
  
      }
      }
  </code></pre>
  
  <p>i sorted out the problem , is there any other way around for comparing the numbers rather than setting a value for min and max ?</p>
  
  <pre><code>import java.util.Scanner;
      public class determine {
  
      public static void main (String [] args) {
  
              int max=-9999;
              int min=9999;
  
          Scanner scan=new Scanner(System.in);
  
  
              System.out.println("enter 5 numbers : ");
              for(int i=1; i&lt;=5; i++){
              int num=scan.nextInt();
  
  
                      if (num&gt;max){max=num;}
                      if(num&lt;min){min=num;}       
              }   
  
                          System.out.println(max+"largest");  
                          System.out.println(min+"smallest");
  
  
          }
  
  
      }
  </code></pre>