I could get the largest without using arrays but, unable to get the smallest one.
public static void main(String[] args)
{
int smallest=0;
Try this :
int smallest = Integer.MAX_VALUE;
for(int i=0;i<n;i++)
{
num=input.nextInt();
if(num>large)
{
large=num;
}
if(num<smallest){
smallest=num;
}
public class Main {
public static void main(String[] args) {
int i = 10;
int j = 20;
int k = 5;
int x = (i > j && i > k) ? i : (j > k) ? j : k;
int y = (i < j && i < k) ? i : (j < k) ? j : k;
System.out.println("Largetst Number : "+x);
System.out.println("Smallest Number : "+y);
}
}
Output:
Largetst Number : 20
Smallest Number : 5