Write a java program to print students mark list. Calculate the total and average of the student marks.
Inputs are stuname, register number and five marks.
Total=m1+m2+m3+m4+m5
Avg=total/5
Using scanner class
Please answer it correctly
I will mark you as brainlist
Please answer it very fast
Answers
Sample program in Java:
import java.util.*;
class Brainly
{
public static void main(String args[])
{
String name;
int reg, m1,m2,m3,m4,m5;
float total, Avg;
Scanner demo = new Scanner(System.in);
System.out.print("Enter Student name: ");
name = demo.nextLine();
System.out.print("Enter regd.number: ");
reg = demo.nextInt();
System.out.println("Enter marks obtained in 5 subjects: ");
m1 = demo.nextInt();
m2 = demo.nextInt();
m3 = demo.nextInt();
m4 = demo.nextInt();
m5 = demo.nextInt();
total = m1 + m2 + m3 + m4 + m5;
Avg = total/5;
System.out.println("Total marks = " + total);
System.out.println("Average = " + Avg);
}
}
Output:
Enter student name: Siddhartha
Enter regd.number: 538
Enter marks obtained in 5 students:
100
200
300
400
500
Total marks = 1500.0
Avg = 300.0
Note: In order to meet your requirements, i have solved in this way. We can solve it using for loop also.That will be less efficient.
<!Hope this helps ----- >
Hope it helps!
CODE :
import java.util.*;
class I_hate_studies//give the name Average if u hate me :-(
{
public static void main(String args[])
{
Scanner jishnu =new Scanner(System.in);//your loving Scanner class
System.out.println("Enter the name of your dear student");
String name=jishnu.nextLine();
System.out.println("Dear enter the register number please");
int reg=jishnu.nextInt();
System.out.println("Last one sorry for troubling..... enter marks of 5 subjects");
int m1=jishnu.nextInt();
int m2=jishnu.nextInt();
int m3=jishnu.nextInt();
int m4=jishnu.nextInt();
int m5=jishnu.nextInt();
int total = m1+m2+m3+m4+m5;
double average=total/5.0;
System.out.println(" MARKS LIST OF "+name);
System.out.println();
System.out.println("Total marks obtained ="+total);
System.out.println("Average marks = "+average);
}//end of main uff relieved
}//end of class hurray
========================================================
EXPLANATION :
⇒ Scanner class is created by the key word " new "
⇒ System.out.println is used for printing the very next line !
⇒ The Blue J version which is more than 3.0 may not give static keyword.
⇒ They can write public void main()
⇒ First we take all inputs , then we add the marks in variable total
⇒ Ultimately average = sum of all marks { total } / number of subjects
⇒ I have taken the average in double for accuracy in calculation !
⇒ I used BlueJ to compile
⇒ The output screen in the attachment.
==============================================================
OUTPUT :
I_hate_studies.main({ });
Enter the name of your dear student
Jishnu
Dear enter the register number please
000000001
Last one sorry for troubling..... enter marks of 5 subjects
5
12
56
100
1
MARKS LIST OF Jishnu
Total marks obtained =174
Average marks = 34.8
=============================================================
Hope it helps you :-)
Sorry for late :-(
_____________________________________________________________________