81.1k views
5 votes
write a java program that prints a table with a list of at least 5 band’s attendance with their total attendance (venue 1, venue 2, and the total) in the format below

1 Answer

3 votes

Final answer:

To print a table with a list of at least 5 band's attendances and their total attendance in Java, you can use a combination of arrays and loops.

Step-by-step explanation:

To print a table with a list of at least 5 band's attendances and their total attendance in Java, you can use a combination of arrays and loops. Here is an example program:




public class BandAttendance {
public static void main(String[] args) {
String[] bands = {"Band A", "Band B", "Band C", "Band D", "Band E"};
int[][] attendance = {{100, 150}, {200, 100}, {300, 200}, {250, 300}, {150, 150}};

System.out.println("Bands Attendance Table");
System.out.println("---------------------");
System.out.println("Band\tVenue 1\tVenue 2\tTotal Attendance");

for (int i = 0; i < bands.length; i++) {
int totalAttendance = attendance[i][0] + attendance[i][1];
System.out.println(bands[i] + "\t" + attendance[i][0] + "\t" + attendance[i][1] + "\t" + totalAttendance);
}
}
}



This program creates two arrays: one for the band names and another for the attendance numbers. It then uses a for loop to iterate over the arrays and calculate the total attendance for each band. The table is printed using the System.out.println() method.

User Thekbb
by
7.3k points