Knowledge Walls Java Master Hyderabad, Andhra Pradesh, India
Find Big and Small Number from a Array in Java
 7716 Views
 Output  Enter the num 12 23 34 10 12==12 23==12 34==23 10==34 Lareg Num:34=Small Num=10 EasiestExample ```import java.util.Arrays; import java.util.Collections; class EasiestExample {     public static void main(String args[]) {      Integer numbers[] = {10,20,40};      System.out.println(Collections.max(Arrays.asList(numbers)));      System.out.println(Collections.min(Arrays.asList(numbers)));     } }``` Output  40 10 Hints  First example is used to find large and small number using algorithm. and the second one is already created algorith with java standard edition library and Arrays.asList used to convert array of string to List of string. Collections.max returning big number in the list. and Collections.min returning small number from the list. MyObjectExample ```import java.util.Scanner; class MyObjectExample {     public static void main(String args[]) {         System.out.println("Enter the num");         Scanner a = new Scanner(System.in);         int x = a.nextInt();         int y = a.nextInt();         int z = a.nextInt();         int x1 = a.nextInt();         int[] arr = { x, y, z, x1 };         int large = arr;         int small = arr;         for (int i = 0; i < arr.length; i++) {             System.out.println(arr[i] + "==" + large);             if (arr[i] > large) {                 large = arr[i];             }             if (arr[i] < small) {                 small = arr[i];             }         }         System.out.println("Lareg Num:" + large + "=Small Num=" + small);     } }```
Next Topics
Next lessons of current book.
Previous Topics
Previous lessons of current book.
Best Lessons of "Core Java"
Top lessons which are viewed more times.     Top authors Hot Updates      