Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the logic for Q_04_24 #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions Exercise_04/Exercise_04_24/Exercise_04_24.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,26 @@ public static void main(String[] args) {
String city3 = input.nextLine();

String temp;
if ((city2.compareTo(city1) < 0) && (city2.compareTo(city3) < 0))
{
temp = city1;
city1 = city2;
city2 = temp;
}
else if ((city3.compareTo(city1) < 0) && (city3.compareTo(city2) < 0))
{
temp = city1;
city1 = city3;
city3 = temp;

}
if (city3.compareTo(city2) < 0)
{
temp = city2;
city2 = city3;
city3 = temp;
}

if ( city1.compareTo(city2) > 0) {
temp = city1;
city1 = city2;
city2 = temp;
}

if( city1.compareTo(city3) > 0) {
temp = city1;
city1 = city3;
city3 = temp;
}

if( city2.compareTo(city3) > 0 ) {
temp = city2;
city2 = city3;
city3 = temp;
}
// Display cities in ascending order
System.out.println("The three cities in alphabetical order are " +
city1 + " " + city2 + " " + city3);
}
}
}