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, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment