Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java coding 11. Prompt the user for a letter grade and store this in a char. The

ID: 3877919 • Letter: J

Question

Java coding

11. Prompt the user for a letter grade and store this in a char. Then, write a multi-way "if" statement that ends ina catch-all if a non-existent letter grade (i.e., not A, B, C, D, F) is entered. The multi-way "if" asks: Is the grade an "A"? Else is the grade a "B"? Else is the grade a "C"? Else is the grade a "D? Else is the grade an "F"? For each case, print an appropriate message to screen as to what letter grade was entered (or if a non-existent grade was entered). Notice the use of the word else in the sentence above, which provides for a more precise meaning. In spoken English we might use the word "or" instead, but of course, English is terribly ambiguous and Java needs to be discrete, deterministic, and precise. 12. Write a function called "max" that takes two integers as input and returns the larger of the two. That is, complete the function "public static int max(int a, int b) f" so that it returns the larger of a or b using an "if statement. 13. Ask the user for two integers using a Scanner and report the largest and smallest values using the max function you just built. Consider the following output: //sample output for problem 13 Enter two integers: 2 14 Largest is 14 Smallest is2

Explanation / Answer

11)

import java.util.Scanner;
public class Grade1 {

  

public static void main(String[] args) {
  
Scanner sc = new Scanner(System.in);
System.out.print("Enter a letter grade: ");
char grade = sc.nextLine().charAt(0);
if (grade == 'A') {
System.out.println("You enter grade " + grade);
}
else if (grade == 'B') {
System.out.println("You enter grade " + grade);
}
else if (grade == 'C') {
System.out.println("You enter grade " + grade);
}
else if (grade == 'D') {
System.out.println("You enter grade " + grade);
}
else if (grade == 'F') {
System.out.println("You enter grade " + grade);
}
else {
System.out.println("You enter invalid grade " + grade);
}
  
sc.close();
}

OUTPUT

Enter a letter grade: A
You enter grade A

12)

public static int max(int a, int b){

if(a>b){

return a;

}

else

return b;

}

13)

import java.util.Scanner;

public class Max {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter two Integer :");

int first = scan.nextInt();

int second = scan.nextInt();

int largest = max(first,second);

int smallest = min(first,second);

System.out.println("Largest number is"+largest);

System.out.println("Smallest number is "+smallest);

}

public static int max(int a, int b){

if(a>b){

return a;

}

else

return b;

}

public static int min(int a, int b){

if(a>b){

return b;

}

else

return a;

}

}

OUTPUT

Enter two Integer : 2 14
Largest number is14
Smallest number is 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote