Java program to find the largest & smallest number in n numbers without using arrays

前端 未结 8 1134
天命终不由人
天命终不由人 2020-12-22 14:22

I could get the largest without using arrays but, unable to get the smallest one.

    public static void main(String[] args)
    {
        int smallest=0;
           


        
8条回答
  •  没有蜡笔的小新
    2020-12-22 15:00

    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

提交回复
热议问题