Write a java program to calculate the grade
depending on the marks entered .
marks <50 - Fail
Marks >= 50 and Marks <60- Grade C
marks>= 60 & marks <70- Grade B
Mark>= 70 and Marks <80 - Grade A
marks >= 80 - GradeA+
Answers
Answer:
import java.util.Scanner;
public class CalculateGrade {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.print("Enter Marks to Know Grade : ");
float marks = kb.nextFloat();
if(marks<50){
System.out.println("Fail");
}else if(marks>=50 && marks<60){
System.out.println("Grade C");
}else if(marks>=60 && marks<70){
System.out.println("Grade B");
}else if(marks>=70 && marks<80){
System.out.println("Grade A");
}else if(marks>=80){
System.out.println("Grade A+");
}
}
}
Explanation:
Answer:
#include <iostream>
using namespace std;
int main(){
int marks;
cout<<"Enter your marks"<<endl;
cin>>marks;
if(marks<50){
cout<<"Fail"<<endl;
}else{
if(marks>=50&& marks<60){
cout<<"Grade C"<<endl;
}else{
if(marks>=60 && marks <70){
cout<<"Grade B"<<endl;
}else{
if(marks >=70 && marks <80){
cout<<"Grade A"<<endl;
}else{
if(marks>=80){
cout<<"Grade A+"<<endl;
}
}
}
}
}
return 0;
}
Explanation:
I used C++ to answer your question because I realised the answer in Java have been given already. This might be an added advantage though.