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

Can someone help me figure out why when i print the table, the last line is spac

ID: 3872790 • Letter: C

Question

Can someone help me figure out why when i print the table, the last line is spaced out and is misaligned with the rest of the table? All the labels and numbers are fine except the last line that looks like its tabbed twice instead of once like the rest of the numbers.

package employeeSalary;

public class SalaryRates {

   public static void main(String[] args) {

      

           String []level = {"Entry Level", "Mid-Level", "Senior Level"};

           String []rank = {"Enlisted", "C.W.O.", "Officer", "Contractor"};

           double [][] type = {{1479.30, 3052.00, 5926.50},

           {2966.40, 4702.50, 7436.10},

           {3034.80, 6009.30, 15583.20},

           {49000, 74579, 100000}};

           System.out.print(" ");

           for(int i=0;i<level.length;i++){

           System.out.print(level[i]+ " ");

           }

           System.out.println();

           for(int i=0;i<rank.length;i++){

           System.out.print(rank[i]+ " ");

           for(int j=0; j<type[i].length;j++){

           System.out.print(type[i][j]+ " ");

           }

           System.out.println();

           }

   }

}

Explanation / Answer

Sample Output


public class Main {

public static void main(String[] args) {
  
String []level = {"Entry Level", "Mid-Level", "Senior Level"};

String []rank = {"Enlisted", "C.W.O.", "Officer", "Contractor"};

double [][] type = {{1479.30, 3052.00, 5926.50},

{2966.40, 4702.50, 7436.10},

{3034.80, 6009.30, 15583.20},

{49000, 74579, 100000}};

System.out.print(" ");

for(int i=0;i<level.length;i++){

System.out.print(level[i]+ " ");

}

System.out.println();

for(int i=0;i<rank.length;i++){

// Modified this line. Since word Contractor is comparitively of more length, there was an issue.
// printf means print format. Now each word in first column are occupying 10 characters space.
System.out.printf("%-10s ",rank[i]);

for(int j=0; j<type[i].length;j++){

System.out.print(type[i][j]+ " ");

}

System.out.println();

}
}
}

Sample Output

                  Entry Level     Mid-Level       Senior Level      Enlisted        1479.3          3052.0          5926.5            C.W.O.          2966.4          4702.5          7436.1            Officer         3034.8          6009.3          15583.2           Contractor      49000.0         74579.0         100000.0  
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