Sun Oct 31, 2010 8:14 pm
import java.util.Scanner;
public class NondescendingOrder {
public static void main (String[] args) {
// declares variables
int a,b,c;
Scanner input= new Scanner (System.in);
// ask user for input
System.out.print("Please enter three numbers separated by space: ");
// read and store the input
a= input.nextInt();
b= input.nextInt();
c= input.nextInt();
//output of input
System.out.println ("Input 1= " +a);
System.out.println ("Input 2= " +b);
System.out.println ("Input 3= " +c);
// if and else statement
if (a<b) {
if (b<c)
System.out.println("The order is: "+a+" "+b+" "+c);
else
System.out.println("The order is: "+a+" "+c+" "+b);
}
else if (b<a){
if (a<c)
System.out.println("The order is: "+b+" "+a+" "+c );
else
System.out.println("The order is: "+b+" "+c+" "+a );
}
else if (c<a){
if (b<a)
System.out.println("The order is: "+c+" "+a+" "+b);
else
System.out.println("The order is: "+c+" "+b+" "+a);
}
}
}
Mon Nov 01, 2010 11:40 am
if (a<=b) {
if (b<c)
System.out.println("The order is: "+a+" "+b+" "+c);
else
System.out.println("The order is: "+a+" "+c+" "+b);
}
else if (a<=c){
System.out.println("The order is: "+b+" "+a+" "+c );
}
else {
if (b<c)
System.out.println("The order is: "+b+" "+c+" "+a);
else
System.out.println("The order is: "+c+" "+b+" "+a);
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.