Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Week7 Java

The document contains a Java program that prompts the user to enter three names. It then compares the names lexicographically and prints them in alphabetical order. The program uses the Scanner class for input and conditional statements for comparison and output.

Uploaded by

77fgj8j2jk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Week7 Java

The document contains a Java program that prompts the user to enter three names. It then compares the names lexicographically and prints them in alphabetical order. The program uses the Scanner class for input and conditional statements for comparison and output.

Uploaded by

77fgj8j2jk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Scanner meed = new Scanner(System.

in);
System.out.println("Enter your name:");
String name1 = meed.next();

System.out.println("Enter your second name:");


String name2 = meed.next();

System.out.println("Enter your third name:");


String name3 = meed.next();
System.out.println(" ");

if (name1.compareTo(name2)<0){
if (name1.compareTo(name3)<0){
System.out.println(name1);
System.out.println(name2);
System.out.println(name3);
}
else{
System.out.println(name3);
System.out.println(name1);
System.out.println(name2);
}
}
else {
if (name2.compareTo(name3)<0){
System.out.println(name2);
System.out.println(name3);
System.out.println(name1);
}
else{
System.out.println(name3);
System.out.println(name2);
System.out.println(name1);
}
}

You might also like