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

前端 未结 8 1073
天命终不由人
天命终不由人 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 14:56

    Try this...This simple

    import java.util.Scanner;
    
    class numbers
    {
       public static void main(String args[])
       {
          int x, y, z;
          System.out.println("Enter three integers ");
          Scanner in = new Scanner(System.in);
    
          x = in.nextInt();
          y = in.nextInt();
          z = in.nextInt();
    
          if ( x > y && x > z )
             System.out.println("First number is largest.");
          else if ( y > x && y > z )
             System.out.println("Second number is largest.");
          else if ( z > x && z > y )
             System.out.println("Third number is largest.");
          else   
             System.out.println("Entered numbers are not distinct");
       }
    }
    

提交回复
热议问题