Monday, August 19, 2019

Program on 2 D Array On Marks and Roll Number

This is a typical BlueJ program on marks and roll numbers of number of students stored in 2-d array.


The annual exam result of 50 students of a class X A of Kerala Public School is tabulated as follows:

Roll No       SubjectA       SubjectB    SubjectC

Write a program in Java to read the data and determine:
(1)Total marks obtained by each student
(2) Highest marks in each subject and Roll No of the student who obtained it
(3) Highest Total marks along with Roll Number


import java.util.*;
public class Marks
{
    Scanner sc=new Scanner(System.in);
    int i,j,max,maxi,total;
    int marks[][]=new int [50][5];
   
   
    public void input()
    {           
            for(i=0;i<=49;i++)
            {
                System.out.println("\nEnter Roll Number of Student No "+(i+1)+"; ");
                marks[i][0]=sc.nextInt();
                total=0;
                 for(j=1;j<=3;j++)
                 {
                    System.out.println("\nEnter Marks of Subject No "+j+"; ");
                marks[i][j]=sc.nextInt();
                total=total+marks[i][j];
                 }
                 marks[i][j]=total;
             }
            }
        public void show ()
        {
           
           System.out.println("\nMarks Obtained by Each Student");
           System.out.println("\nRoll  SubjectA  SubjectB  SubjectC  Total");
           for(i=0;i<=49;i++)
           {
               for(j=0;j<=4;j++)
               {
                   System.out.print(marks[i][j]+"        ");
                }
                 System.out.println();
            }
        System.out.println("\nHighest Marks in SubjectA with Roll No");
        max=marks[0][1];
        maxi=marks[0][0];
        for(i=1;i<=49;i++)
        {
            if(marks[i][1] >max)
            {
                 max=marks[i][1];
                 maxi=marks[i][0];
                }
            }
            System.out.print("Roll No:" + maxi+ " Marks Obtained:"+ max);
           
            System.out.println("\nHighest Marks in SubjectB with Roll No");
        max=marks[0][2];
        maxi=marks[0][0];
        for(i=1;i<=49;i++)
        {
            if(marks[i][2]>max)
            {
                 max=marks[i][2];
                 maxi=marks[i][0];
                }
            }
                        System.out.print("Roll No:" + maxi+ " Marks Obtained:"+ max);
                       
            System.out.println("\nHighest Marks in SubjectC with Roll No");
        max=marks[0][3];
        maxi=marks[0][0];
        for(i=1;i<=49;i++)
        {
            if(marks[i][3 >max)
            {
                 max=marks[i][3];
                 maxi=marks[i][0];
                }
            }
                        System.out.print("Roll No:" + maxi+ " Marks Obtained:"+ max);
           
                        
                        System.out.println("\nHighest Total Marks with Roll No");
        max=marks[0][4];
        maxi=marks[0][0];
        for(i=1;i<=49;i++)
        {
            if(marks[i][4] >max)
            {
                 max=marks[i][4];
                 maxi=marks[i][0];
                }
            }
                        System.out.print("Roll No:" + maxi+ " Marks Obtained:"+ max);
    }
          
            public static void main(String args[])
            {
                 Marks obj=new Marks();
                 obj.input();
                 obj.show();
             }
            }

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner