for loop

ive been trying to write a code that takes in three integers and sorts them from smallest to largest but I keep getting the wrong output from my if loops

import java.util.*;
public class Ch4Pr1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int x;
int y;
int z;

System.out.println("Enter three integers: ");
x =input.nextInt();
y= input.nextInt();
z= input.nextInt();

System.out.println("The inputs in sorted order are: ");

// print the smallest number
if (xy)
{
{
if (y>z)
System.out.println(y);
}
}
if (y>x)
{
{
if (xx)
{
{
if(y>z)
System.out.println(z);
}
}
// print the largest number
if (x>y)
{
{
if (x>z)
System.out.println(x);
}
}
if (y>x)
{
{
if (y>z)
System.out.println(y);
}
}
if (z>x)
{
{
if (z>y)
System.out.println(z);
}
}
}
}



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories