Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Biggest and Smallest Number in Array in Java

This program Finds the Largest Number and the Smallest Number present in the Array Variable.
It uses for loop to iterate the array upto the end of its index value and if conditions evaluates the biggest and smallest numbers and
that store in the specified variable.
  1. public class FindBiggestSmallestNumber {
  2. public static void main(String[] args) {
  3. int numbers[] = new int[]{33,53,73,94,22,45,23,87,13,63};
  4. int smallest = numbers[0];
  5. int biggest = numbers[0];
  6. for(int i=1; i< numbers.length; i++)
  7. {
  8. if(numbers[i] > biggest)
  9. biggest = numbers[i];
  10. else if (numbers[i] < smallest)
  11. smallest = numbers[i];
  12. }
  13. System.out.println("Largest Number is : " + biggest);
  14. System.out.println("Smallest Number is : " + smallest);
  15. }
  16. }