Credits

Saturday, February 28, 2009

More Java Single Array Sample

Check other sample programs of the single dimensional array in Java.



[+/-] show/hide


//program to check largest/smallest number
class onedarray{
public static void main (String [] args){
int sample[]={99,-10,100123,18,-978,5623,463,-9,287,49};
int i,min,max;
min=max=sample[0];
for(i=0;i<10;i++)
{ if (sample[i]>min)
min=sample[i];
if (sample[i]\ /* the slash symbol means to concatenate the next line*/
max==sample[i];}

System.out.println("The lowest number is "+min );
System.out.println("The largest number is "+max );
}
}

The output is expected to display the lowest and largest number from the initial elements given.

AddThis