Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions