Question

Use printf(...) method to Write a java program that asks the user to enter three different...

Use printf(...) method to Write a java program that asks the user to enter three different names and then sorts and display names in ascending order. For example, if the names "Maria", "Kelley", and "Angie" were entered, the program will display: Names in sorted order are: FIRST: Angie SECOND: Kelley THIRD: Maria

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output:

Code will be like:

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{

String temp;
String names[] = new String[3];
Scanner s1 = new Scanner(System.in);
System.out.println("Enter three names:");
for(int i = 0; i < 3; i++)
{
names[i] = s1.nextLine();
}
for (int i = 0; i < 3; i++)
{
for (int j = i + 1; j < 3; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.print("Names in Sorted Order are:");
for (int i = 0; i < 3 - 1; i++)
{
System.out.print(names[i] + ",");
}
System.out.print(names[3 - 1]);
}
}

Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.

Add a comment
Know the answer?
Add Answer to:
Use printf(...) method to Write a java program that asks the user to enter three different...
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
  • LANGUAGE: JAVA Sorting an array: 2. Write a program that asks the user for 5 numbers...

    LANGUAGE: JAVA Sorting an array: 2. Write a program that asks the user for 5 numbers and stores them in an array called data. Then call a method that accepts the array as an argument, sorts the array in ascending order and prints out the original AND sorted array (Hint: The method does not return anything in this case, so it should be set to void).

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • Create a Java program which asks the user how many names they want to enter. The...

    Create a Java program which asks the user how many names they want to enter. The program should then instantiate an array that will hold this many names. The main method should call a method, getNames() to allow the user to enter the names. A for loop should be used in this method. Once the names are entered, the main method should call another method displayNames() which will use a while loop to display the names entered.

  • In Java, write a program using a loop that asks the user to enter a series...

    In Java, write a program using a loop that asks the user to enter a series of decimal numbers. The user must enter -88 to end the input of the decimal numbers. After the user enters all numbers, the program should display the sum of all numbers entered.

  • ***** JAVA ONLY ***** Write a program that asks the user to enter the name of...

    ***** JAVA ONLY ***** Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad to create a simple file that can be used to test the program. ***** JAVA ONLY *****

  • Write a program in Java language to prompt the user to enter 3 integers (A, B,...

    Write a program in Java language to prompt the user to enter 3 integers (A, B, and C) then display these numbers from the lowest to the highest (sorted ascendingly) . Note that there are 6 different cases to handle proper order. As an example, a user entered 10 for A, 5 for B and 14 for C: the output of the program should look like this Enter number A? 10 Enter number B? 5 Enter number C? 14 Your...

  • Java Letter Counter: Write a program that asks the user to enter a string, and then...

    Java Letter Counter: Write a program that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. Must use a do while loop and a counter!!!!

  • Write a program in JAVA that asks the user to enter an integer. Store the integers...

    Write a program in JAVA that asks the user to enter an integer. Store the integers in an array. Allow for up to 10 integers. When the user enters -1, the program should end. Print the number of integers entered as well as the number of times each integer was entered.

  • write a program that asks the user to enter two integers one at a time if...

    write a program that asks the user to enter two integers one at a time if the first value is not an integer then do not ask for a second then display both values otherwise print error message stating which value entered was not an integer python

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

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