mercredi 3 mars 2021

Display 3 numerical values ​in java with greater, less and equal

I'm trying to show 3 different values in this code, the highest number, the lowest number and if all the numbers are the same the output should show that they are equal, So far I have only been able to show greater or equal values, but I don't know how to implement the display of the smaller value, does this structure help me to achieve it or should I use another type of structure?

    import java.util.Scanner;

public class values

{
    public static void main(String[] args) 

    {
        int x, y, z;

        Scanner s = new Scanner(System.in);

        System.out.print("First Value:");

        x = s.nextInt();

        System.out.print("Second Value:");

        y = s.nextInt();

        System.out.print("Third Value:");

        z = s.nextInt();

        if (x == y && x == z)
    {
        System.out.println("All numbers are equal");
        
    }
        else if(y > z && y > x)

        {
            System.out.println("The highest value is: "+y);

        }
        else if(x > y && x > z)

        {
            System.out.println("The highest value is: "+x);
        }
        else

        {
            System.out.println("The highest value is: "+z);
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire