Question

THIS QUESTION HAS TWO PARTS: A) Write an application that accepts three Strings from the user...

THIS QUESTION HAS TWO PARTS:

A) Write an application that accepts three Strings from the user and displays one of two messages depending on whether the user entered the Strings in alphabetical order without regard to case.

Save the file as Alphabetize.java.

B) Write an application that accepts three Strings from the user and displays them in alphabetical order without regard to case.

Save the file as Alphabetize2.java

Homework Answers

Answer #1

Alphabetize.java

import java.util.*;
public class Alphabetize{

public static void main(String []args){
Scanner sc=new Scanner(System.in);

System.out.println("Enter 1st string");
String s1=sc.next();
System.out.println("Enter 2nd string");
String s2=sc.next();
System.out.println("Enter 3rd string");
String s3=sc.next();   
  
if(s2.compareTo(s1)>0 && s3.compareTo(s2)>0)
System.out.println(" strings are in alphabetical order");
else
System.out.println(" strings are NOT in alphabetical order");
}
}

output:

Alphabetize2.java

import java.util.*;
public class Alphabetize2{

public static void main(String []args){
String temp;
Scanner sc=new Scanner(System.in);

System.out.println("Enter 1st string");
String s1=sc.next();
System.out.println("Enter 2nd string");
String s2=sc.next();
System.out.println("Enter 3rd string");
String s3=sc.next();   

if (s1.compareTo(s2)>0)
{
temp =s1;
s1 = s2;
s2 = temp;
}
if (s2.compareTo(s3)>0)
{
temp =s2;
s2 = s3;
s3 = temp;
}
if (s1.compareTo(s3)>0)
{
temp =s1;
s1 = s3;
s3 = temp;
}
System.out.print("strings in Sorted Order:");
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
}
}

:

Know the answer?
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
Similar Questions
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. This is a java assignment. Pls help
1) the source code (.java file), and 2) the screenshot of running results of each question....
1) the source code (.java file), and 2) the screenshot of running results of each question. (Comparing Portions of Strings) Write an application to compare two strings input by the user. The application should state whether the strings are equal. Ignore the case of the characters when performing the comparison.
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. ------------------------------------------------------------------------------------------------- import java.util.Scanner; public class Inbetween {     public static void main (String args[]) {         // Write your code here     } }
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
Java Language: Write an application that asks the user to enter a student ID and a...
Java Language: Write an application that asks the user to enter a student ID and a test letter grade. Create an Exception class names GradeException that contains an Array of valid grade letters that you can use to determine whether a grade entered from the application is valid. In your application, throw a GradeException if the user does not enter a valid letter grade. Catch the GradeException, and then display an appropriate message. In addition, store an 'I' (for incomplete)...
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
Write a Java program that reads words from a text file and displays all the words...
Write a Java program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store data from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection or List class.
Write a Java application a String input by the user and shows whether the string contains...
Write a Java application a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. needs, at minimum, asl user to input for the String, then...
IN JAVA: Write code (using ArrayLists) to read a line of input from the user and...
IN JAVA: Write code (using ArrayLists) to read a line of input from the user and print the words of that line in sorted order, without removing duplicates. For example, the program output might look like the following: Type a message to sort: to be or not to be that is the question Your message sorted: be be is not or question that the to to
Q.1. Write a program that accepts the lengths of three sides of a triangle as inputs....
Q.1. Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle. Q.2. Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the...