Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to display output in this way this uses table without border line in java: O

ID: 3903705 • Letter: H

Question

How to display output in this way this uses table without border line in java:

Output:

Method #COMP #ASGN #OPS

------ ----- ----- ----

Bubble 492,818 650,979 1,143,797

Selection 499,500 2,997 502,497

Insertion 217,991 218,991 436,982

Shell 9,879 18,280 28,159

Here is my code:

public static void sortNumbers() {
resetCounts();

Integer[] numbers = randomNumbers(size, min, max);
if (list == 'Y'){
System.out.println("Here is the list: " + Arrays.toString(numbers));
}
  
System.out.println(" "
+ "Method #COMP #ASGN #OPS "
+ "------ ----- ----- ----" );
  
bubbleSort(numbers);
System.out.printf("Bubble "
+ "%,d %,d"
+ " %,d%n%n",
numComp, numAsgn, numAsgn + numComp);

System.out.printf("We expected Bubble sort to take %,d operations "
+ "to sort %,d numbers.%n",
expect(size), size);
  
selectionSort(numbers);
System.out.printf("Selection "
+ "%,d %,d"
+ " %,d.%n%n",
numComp, numAsgn, numAsgn + numComp);
  
insertionSort(numbers);
System.out.printf("Insertion "
+ "%,d %,d"
+ " %,d.%n%n",
numComp, numAsgn, numAsgn + numComp);
  
shellSort(numbers);
System.out.printf("Shell "
+ "%,d %,d"
+ " %,d.%n%n",
numComp, numAsgn, numAsgn + numComp);
}

public static void main(String[] args) {

sortNumbers();

Explanation / Answer

The relevant code segment can be

System.out.printf("%20s%15s%15s%15s ","Method","#COMP", "#ASGN", "#OPS");
System.out.printf("%20s%15d%15d%15d ",numComp, numAsgn, numAsgn + numComp);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote