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. ------------------------------------------------------------------------------------------------- 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.
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
JAVA Write a program that has two functions in which the user chooses which one to...
JAVA Write a program that has two functions in which the user chooses which one to perform; 1. reads in a CSV file of integers into an array and insert it into a binary search tree class 2. deserializes an object and inserts it into a binary search tree class the tree class must be in a separate class from the CSV file read and deserialize object load
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
Problem: Read in a word and display the requested characters from that word in the requested...
Problem: Read in a word and display the requested characters from that word in the requested format. Write a Java program that ● prompts the user for a word and reads it, ● converts all characters of the input word to upper case and displays every character whose index is a multiple of 3 starting from the 1st one, ● next converts all characters of the input word to lower case and displays the word with the characters in reverse...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT