Question: Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter
Write a console program that repeatedly prompts the user to enter data until they type done
(any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two-dimension array
where the first dimension contains exactly what they type and the second dimension contains
the first non-whitespace character of what they type, in lowercase. If they enter a blank line, it
is acceptable to skip that line. When they type done, do these steps:
1. display: As Entered
2. for each entry in the array, display the index of the first dimension, the second
dimension's value, and the first dimension's value on a single line separated by :
(colon).
3. display: Bubble Sorted
4. using a bubble sort, for each entry in the array, display the original index of the first
dimension, the second dimension's value, and the first dimension's value on a single
line separated by : (colon) sorted by the second dimension.
5. display: Selection Sorted
6. using a selection sort, for each entry in the array, display the original index of the first
dimension, the second dimension's value, and the first dimension's value on a single
line separated by : (colon) sorted by the first dimension.
Correct .JAVA file: The program must store the values entered by the user in a 2-dimensional array and do a bubble-sort and a selection-sort on the data.
import java.util.Scanner;
/** * * Date: 08/25/2017 * Assignment: A4 * Student Number: MA5331550 * Description: This program repeatly prompts the user to user to enter data until they type done. Ask data is
entered it assigned to a two-dimension array. */ public class A4MA5331550 { public static void main(String args[]) { // Create a Scanner to read from System Input like Keyboard. Scanner input = new Scanner(System.in); String data = ""; // Create an infinite loop by placing the while loop condition as 'true' // so that it will always be true. while (true) { System.out.println("Enter your data: "); // Read from the input device via Scanner data = input.next(); // Ignoring the case, if the data entered is 'done' then break and // exit the loop. if (data.equalsIgnoreCase("done")){ System.out.println("Done, BYE!"); break; } System.out.println("You have entered: " + data); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
