Output
Enter the num
12
23
34
10
12==12
23==12
34==23
10==34
Lareg Num:34=Small Num=10
|
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)));
}
}
|
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.
|
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[0];
int small = arr[0];
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);
}
}
|