Using if-else statement import java.util.*; public class GradeWithIfElse { publi
ID: 3805550 • Letter: U
Question
Using if-else statement
import java.util.*;
public class GradeWithIfElse {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter the marks: ");
int g = s.nextInt();
char grade='F';
if(g>=90)
grade='A';
else if(g>=80&&g<90)
grade='B';
else if(g>=70&&g<80)
grade='C';
else if(g>=60&&g<70)
grade='D';
else if(g<60)
grade='F';
System.out.println("Grade is: "+grade);
}
}
code this using dialog box in java JOptionPane
Explanation / Answer
Scanner s = new Scanner(System.in);
System.out.print("Enter the marks: ");
int g = s.nextInt();
char grade='F';
if(g>=90)
grade='A';
else if(g>=80&&g<90)
grade='B';
else if(g>=70&&g<80)
grade='C';
else if(g>=60&&g<70)
grade='D';
else if(g<60)
grade='F';
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.