JAVA Programming:-
Write a program in Java to assume the total marks obtained by a student in Computer Exam out of 100 & display the Grade of
that student along with the marks as per following format:
Marks Grade
Below 50 Fail
50 to 59 D
60 to 69 C
70 to 79 B
80 to 89 A
90 to 100 A+
Answers
Answer:
import java.util.Scanner;
public class JavaExample
{
public static void main(String args[])
{
/* This program assumes that the student has 6 subjects,
* thats why I have created the array of size 6. You can
* change this as per the requirement.
*/
int marks[] = new int[6];
int i;
float total=0, avg;
Scanner scanner = new Scanner(System.in);
for(i=0; i<6; i++) {
System.out.print("Enter Marks of Subject"+(i+1)+":");
marks[i] = scanner.nextInt();
total = total + marks[i];
}
scanner.close();
//Calculating average here
avg = total/6;
System.out.print("The student Grade is: ");
if(avg>=80)
{
System.out.print("A");
}
else if(avg>=60 && avg<80)
{
System.out.print("B");
}
else if(avg>=40 && avg<60)
{
System.out.print("C");
}
else
{
System.out.print("D");
}
}
}
Output:
Enter Marks of Subject1:40
Enter Marks of Subject2:80
Enter Marks of Subject3:80
Enter Marks of Subject4:40
Enter Marks of Subject5:60
Enter Marks of Subject6:60
The student Grade is: B
Answer:
import java.util.Scanner;
public class GradeCalculator {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Computer marks =");
double marks = scan.nextDouble();
if(marks >= 90 && marks <=100){
System.out.println("Grade obtained = A+");
}else if(marks < 90 && marks >= 80){
System.out.println("Grade obtained = A");
}else if(marks < 80 && marks >= 70){
System.out.println("Grade obtained = B");
}else if(marks < 70 && marks >= 60){
System.out.println("Grade obtained = C");
}else if(marks < 60 && marks >= 50){
System.out.println("Grade obtained = D");
}else {
System.out.println("Failed!");
}
}
}
Explanation: