Biyernes, Setyembre 20, 2013

LabExer#21

21. Create a program that will search for the highest and lowest value in an array of 10 elements.



import javax.swing.JOptionPane;

public class HighLowArray{
    public static void main(String[]args){
       
        int x[]=new int[10];
       
        for(int a=0;a<x.length;a++){
            x[a]=Integer.parseInt(JOptionPane.showInputDialog("Enter num["+(a)+"]"));
        }
       
        int high=x[0];
        int low=x[0];
       
        for(int y=0;y<10;y++)
        {
            if(high<x[y]) high=x[y];
            if(low>x[y]) low=x[y];
        }
        JOptionPane.showMessageDialog(null,"The highest number is: " +high);
        JOptionPane.showMessageDialog(null,"The lowest number is: " +low);
       
       
    }
   
}

Walang komento:

Mag-post ng isang Komento