mercredi 19 septembre 2018

JAVA find the highest and lowest number in array with JOptionPane

the code it's for education in college i need the user to insert a values of array and find which number is the highest and lowest but the lowest number doesn't work . can anyone explain this to me , sorry for asking much

     int m=Integer.parseInt(JOptionPane.showInputDialog("Enter index"));       
     int values;
     int num [] = new int [m];

     int max = num[0];
     int min = num[0];
     for (int i=0;i<num.length;i++)      
     {                          
      num[i] = values =Integer.parseInt(JOptionPane.showInputDialog("Enter value"));   
      System.out.println(num[i]);

      if (num[i] > max)
      {
          max=num[i];
      }
      if (num[i] < min )
      {
          min=num[i];
      }

     }                                    
    System.out.println("Largest Number in a given array is : " + max);
    System.out.println("Smallest Number in a given array is : " + min);

Aucun commentaire:

Enregistrer un commentaire