Write a program to input student's name,marks obtained in four different subjects,find the total and average marks.
Answers
Answer:
Explanation:
This is the JAVA program for your question:
import java.util.Scanner;
class student
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter your name");
String name = in.nextLine();
System.out.println("Enter your subject 1 marks");
int m1 = in.nextInt();
System.out.println("Enter your subject 2 marks");
int m2 = in.nextInt();
System.out.println("Enter your subject 3 marks");
int m3 = in.nextInt();
System.out.println("Enter your subject 4 marks");
int m4 = in.nextInt();
double total = m1+m2+m3+m4;
double avg = total/4.0; //the reason why we are writing 4.0 is because we have declared avg to be of a double datatype
System.out.println("Your details:");
System.out.println("Name: " + name);
System.out.println("Total Marks: " + total);
System.out.println("Average of the given marks: " + avg);
}
}
Answer:
Explanation:
import java.util.Scanner;
class student
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter your name");
String name = in.nextLine();
System.out.println("Enter your subject 1 marks");
int m1 = in.nextInt();
System.out.println("Enter your subject 2 marks");
int m2 = in.nextInt();
System.out.println("Enter your subject 3 marks");
int m3 = in.nextInt();
System.out.println("Enter your subject 4 marks");
int m4 = in.nextInt();
double total = m1+m2+m3+m4;
double avg = total/4.0; //the reason why we are writing 4.0 is because we have declared avg to be of a double datatype
System.out.println("Your details:");
System.out.println("Name: " + name);
System.out.println("Total Marks: " + total);
System.out.println("Average of the given marks: " + avg);
}
}