In: Computer Science
Write a program which asks the user for grade, in integer form, from 0 to 100.
If the user's response is negative or greater than 100, insult them.
Otherwise, use if / else statements to print out the letter grade corresponding to the user's input.
Then, write a second version of the program which uses a switch instead of if else. (HINT: divide the user's response by 10)
in java
import java.util.*;
public class Main
{
public static void main(String[] args) {
int n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter mark 0 to
100: ");
n=sc.nextInt();
int i=n;
if(i>=0 &&
i<=100)
{
if(i>=90)
{
System.out.println("A");
}
else if(i>=80)
{
System.out.println("B");
}
else if(i>=70)
{
System.out.println("C");
}
else if(i>=60)
{
System.out.println("D");
}
else
{
System.out.println("F");
}
}
else
{
System.out.println("INVALID");
}
}
}
import java.util.*;
public class Main
{
public static void main(String[] args) {
int n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter mark 0 to
100: ");
n=sc.nextInt();
int i=n/10;
switch(i)
{
case 10:
{
System.out.println("A");
break;
}
case 9:
{
System.out.println("A");
break;
}
case 8:
{
System.out.println("B");
break;
}
case 7:
{
System.out.println("C");
break;
}case 6:
{
System.out.println("D");
break;
}
default:
{
System.out.println("F");
break;
}
}
}
}