Java Program For Student Total Marks

import java.util.Scanner;
class Student1
{
 String name;
 String rollno;
 int[] sub=new int[4];

 void popu()
{
    
   Scanner in = new Scanner(System.in);
   System.out.println(" Enter name");
   name=in.nextLine();
   System.out.println(" Enter number");
   rollno=in.nextLine();
    
   System.out.println("Enter  subject1 ");
                                          
     sub[0] = in.nextInt();
     System.out.println("Enter  subject2 ");
                                          
     sub[1] = in.nextInt();
     System.out.println("Enter  subject13 ");
                                          
     sub[2] = in.nextInt();
     System.out.println("Enter  subject4 ");
                                          
     sub[3] = in.nextInt();
    
}

 int total()
 {
  int k,t=0;
  for(k=0; k<4; k++)
  {
   t= t+sub[k];
   
  }
  return t;
 }

 
}

class StudentDemo1
{
 public static void main(String args[])
{
  int tot;
 Student1 st1= new Student1();
  st1.popu();
     
  tot= st1.total();
 System.out.println(st1.name + "total marks = " +tot);

}
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment