Question: Trying to of-else statement to sort 3 strings . import java.util.*; public class test { public static void main(String[] args) { Scanner scan = new

Trying to of-else statement to sort 3 strings .

import java.util.*;

public class test {

public static void main(String[] args) { Scanner scan = new Scanner(System.in); String w1 = "", w2 ="", w3 = ""; String top = null, mid = null, bot = null; System.out.println("Please enter the first word"); w1 = scan.next(); System.out.println("Please enter the Second word"); w2 = scan.next(); System.out.println("Please enter the third word"); w3 = scan.next(); if(w1.compareTo(w2) > 0 && (w1.compareTo(w3)) > 0) { top = w1; }else if(w1.compareTo(w2) < 0 && (w1.compareTo(w3) > 0)) { mid = w1; } else { bot = w1; } if(w2.compareTo(w1) > 0 && (w2.compareTo(w3)) > 0) { top = w2; }else if(w2.compareTo(w1) < 0 && (w2.compareTo(w3) > 0)) { mid = w2; } else { bot = w2; } if(w3.compareTo(w1) > 0 && (w3.compareTo(w2)) > 0) { top = w3; }else if(w3.compareTo(w2) < 0 && (w3.compareTo(w1) > 0)) { mid = w3; } else { bot = w3; } System.out.println(top); System.out.println(mid); System.out.println(bot); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!