Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class student {
- int s_no;
- String n;
- float total = 0.0f;
- float marks[] = new float[3];
- void getdata(Scanner sc) {
- System.out.print("Student name: ");
- n = sc.nextLine();
- System.out.print("Roll no: ");
- s_no = sc.nextInt();
- System.out.println("Enter marks of 3 subjects:");
- for (int i = 0; i < 3; i++) {
- System.out.print("Subject " + (i + 1) + ": ");
- marks[i] = sc.nextFloat();
- total += marks[i];
- }
- sc.nextLine();
- }
- void display() {
- System.out.print(s_no + "\t" + n + "\t");
- for (int i = 0; i < 3; i++) {
- System.out.print(marks[i] + "\t");
- }
- System.out.println(total);
- }
- public static void main(String args[]) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the number of students: ");
- int n = sc.nextInt();
- sc.nextLine();
- student s[] = new student[n];
- for (int i = 0; i < n; i++) {
- System.out.println("\nEnter the details of student " + (i + 1));
- s[i] = new student();
- s[i].getdata(sc);
- }
- System.out.println("\nSno\tName\tMark1\tMark2\tMark3\tTotal");
- System.out.println("------------------------------------------------------------");
- for (int i = 0; i < n; i++) {
- s[i].display();
- }
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement