public class Main {
public static void main(String[] args) {
String[] monthsNames = { "DEVICE", "JAN", "FEB", "MAR", "TOTAL" };
String[] deviceNames = { "IPhone 7", "Samsung S8", "Huawei Mate 10" };
int[][] monthlySales = { { 30, 15, 35, 80 }, { 20, 25, 30, 75 }, { 25, 11, 32, 68 } };
int[] monthlyTotal = { 75, 51, 97 };
for (int i = 0; i < monthsNames.length; i++) {
if (i == 0) {
System.out.printf("%-17s ", monthsNames[i]);
} else {
System.out.printf("%-8s ", monthsNames[i]);
}
}
System.out.println();
for (int i = 0; i < monthlySales.length; i++) {
System.out.printf("%-17s ", deviceNames[i]);
for (int j = 0; j < monthlySales[i].length; j++) {
System.out.printf("%-8s ", monthlySales[i][j]);
}
System.out.println();
}
System.out.printf("%-17s ", "MONTHLY TOTAL");
for (int i = 0; i < monthlyTotal.length; i++) {
System.out.printf("%-8s ", monthlyTotal[i]);
}
}
}
Comments
Leave a comment