Java program to find greatest number in array:
package arraydemo;
public class ArrayDemo {
public static void main(String[] args) {
int numbers[] = new int[]{11,12,13,44,55,66,77,88,99,23};
int small = numbers[0];
int large = numbers[0];
for(int i=1; i< numbers.length; i++)
{
if(numbers[i] > large)
large = numbers[i];
else if (numbers[i] < small)
small = numbers[i];
}
System.out.println("Largest Number is : " + large);
System.out.println("Smallest Number is : " + small);
}
}
OUTPUT:
Largest Number is : 99
Smallest Number is : 11
0 comments:
Post a Comment