Question

The program prompts the user to input three words, then display them in      sorted order....

The program prompts the user to input three words, then display them in

     sorted order. Strings have to be compared with compareTo method.

*/

import java.util.Scanner;

public class Lab4Part13{

    public static void main(String[] args){

        Scanner input = new Scanner(System.in);

        // Write rest of the code here

    }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class Lab4Part13{

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.print("Enter three strings: ");
        String s1 = input.next(), s2 = input.next(), s3 = input.next(), temp;
        if (s1.compareTo(s2) > 0) {
            temp = s1;
            s1 = s2;
            s2 = temp;
        }
        if (s2.compareTo(s3) > 0) {
            temp = s3;
            s3 = s2;
            s2 = temp;
        }
        if (s1.compareTo(s2) > 0) {
            temp = s1;
            s1 = s2;
            s2 = temp;
        }
        System.out.println("Strings in sorted order are");
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
    }
}
Add a comment
Know the answer?
Add Answer to:
The program prompts the user to input three words, then display them in      sorted order....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Complete the following program so it prompts the user for 3 integers and displays the smallest...

    Complete the following program so it prompts the user for 3 integers and displays the smallest of the 3 numbers. For instance, if the user provided 7 4 and 12, then the program would display 4. import java.util.Scanner; public class Program3{ public static void main(String[] args) { Scanner kb = new Scanner(System.in);

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

  • (Process a string) Write a program that prompts the user to enter a string and displays...

    (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{    public static void main (String args[]){        Scanner input = new Scanner(System.in);        System.out.println("Enter a string:");        String ans = input.nextLine();        System.out.println("The string...

  • Complete the do-while loop to output 0 to countLimit. Assume the user will only input a...

    Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String firstName;       String lastName; //answer goes here//    } }

  • CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to...

    CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector 1 public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; D}]oll kidage = scnr.nextInt(); /* Your solution goes here */ Go USB if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 20 Run Feedback? CHALLENGE ACTIVITY 3.11.2: Boolean in branching statements. Write...

  • Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file...

    Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...

  • Write an expression that executes the loop while the user enters a number greater than or...

    Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...

  • Please put both of this loops into one program. Set it up so that there is...

    Please put both of this loops into one program. Set it up so that there is one main function and both loops are within it. Thank You. import java.util.Scanner; public class WhileDavidMungomaLab12 { public static void main(String[] args) { int aScore = -1; while (aScore < 0 || aScore > 100) { Scanner sc = new Scanner(System.in); System.out.println("Please enter a valid number that is within the specified range(0 and 100): "); aScore = sc.nextInt(); } } } AND import java.util.Scanner;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT