Write a program that reads and records magazine sales for 5 students. Record a
student’s name, the magazine sold, and the number sold. Information should be read
in one record at a time – that is to say, read one student, magazine, and number before
getting the next set. (Similar to the example in the notes.) Produce a table that
displays the recorded information.
Note: use multiple arrays
package q182284;
import java.util.Scanner;
public class Q182403 {
/***
* Main method
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int totalStudents=5;
String [][]studentsData=new String[totalStudents][3];
for (int st = 0; st < totalStudents; st++) {
System.out.print("Enter the student's name: ");
studentsData[st][0]=input.nextLine();
System.out.print("Enter the magazine sold: ");
studentsData[st][1]=input.nextLine();
System.out.print("Enter the number sold: ");
studentsData[st][2]=input.nextLine();
System.out.println();
}
System.out.println(String.format("\n%-30s%-30s%-30s","Student name","Magazine sold","Number sold"));
for (int st = 0; st < totalStudents; st++) {
System.out.println(String.format("%-30s%-30s%-30s",studentsData[st][0],studentsData[st][1],studentsData[st][2]));
}
input.close();
}
}
Comments
Leave a comment