Question

Given an int variable grade, based on its value, assign a char variable letterGrade in the...

Given an int variable grade, based on its value, assign a char variable letterGrade in the following way: 90 and above, ‘A’, 80 ~89, ‘B’, etc in java.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class LetterGrade {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter score: ");
        int value = in.nextInt();
        char letterGrade;
        if (value >= 90) {
            letterGrade = 'A';
        } else if (value >= 80) {
            letterGrade = 'B';
        } else if (value >= 70) {
            letterGrade = 'C';
        } else if (value >= 60) {
            letterGrade = 'D';
        } else {
            letterGrade = 'F';
        }
        System.out.println("grade is " + letterGrade);
    }
}

Add a comment
Know the answer?
Add Answer to:
Given an int variable grade, based on its value, assign a char variable letterGrade in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 14) Given: int grade[4]; grade and &grade[0] can be interchangeable. True False 15) char val[3]; char...

    14) Given: int grade[4]; grade and &grade[0] can be interchangeable. True False 15) char val[3]; char *ptr; ptr = &val[2];      a. will assign the value in val[2] to the pointer     b. will assign the address of val[2] to the pointer    c. results both a and b     d. none 16) In C++, you declare a pointer variable by using the ____ symbol. a. @ b. * c. # d. & 17) Which of the following correctly declares...

  • Assume that an int variable takes 4 bytes and a char variable takes 1 byte. Given...

    Assume that an int variable takes 4 bytes and a char variable takes 1 byte. Given the following integer array: int arr[5] = {12, 10, 13, 90, 1}; Explain the value of arr .  

  • Write a Java program: Given an int array grades int[] grades={89, 80, 78, 60, 38, 92,...

    Write a Java program: Given an int array grades int[] grades={89, 80, 78, 60, 38, 92, 72, 88}, find how many “B” among these grades, (80<=B<90) Print out how many “B”s in this grade.

  • Test Scores and Grade Write a program that has variables to hold three test scores. The...

    Test Scores and Grade Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test scores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table: Test Score Average Letter Grade 90–100 A 80–89 B 70–79 C 60–69 D Below 60...

  • Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; };...

    Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; }; void func(struct student stud); int main() { struct student astud; astud.id=9401; strcpy(astud.name, "Joe"); astud.grade = 'A'; func(astud); return 0; } Abdelghani Bellaachia, CSCI 1121 Page: 16 void func(struct student astud) { printf(" Id is: %d \n", astud.id); printf(" Name is: %s \n", astud.name); printf(" Grade is: %c \n", astud.grade); } Modify this program to include the address of a student as a separate structure....

  • def computeGrade(percentage):     '''     - Return the corresponding letter grade string based on the value...

    def computeGrade(percentage):     '''     - Return the corresponding letter grade string based on the value of     percentage using the following scale:     [100 - 90]: 'A'     (90 - 80] : 'B'     (80 - 70] : 'C'     (70 - 60] : 'D'     (60 - 0] : 'F'     - If percentage is not a number type (int or float) OR if percentage is     outside the range of [100 - 0], return an empty string...

  • Create qz5.c to include all of the following function prototypes: void check1(char *, char, int *);...

    Create qz5.c to include all of the following function prototypes: void check1(char *, char, int *); void check2(char *, char, int *); void display(char, int); Then, implement main() to perform the tasks below: Define a 10-element char array with initial values of any lower case letters of your selection. Values can duplicate. Define a pointer that points to the above array. Print the array completely with double spaces before each character. See screenshot below for a sample. Call check1() with...

  • MATLAB Code: ?MATLAB Code: Write a function that converts a given letter grade it will print...

    MATLAB Code: ?MATLAB Code: Write a function that converts a given letter grade it will print its equivalence in numerical scale. For example if the user enters A, then your function should print a message stating that the grade must be between 90 and 100. B is between 80 and 89, etc. Everything under 60 is F. Use the switch-case function. Use fprintf to display the results on the screen.

  • 1. Given the array grade created as: int [] grade = {75, 80, 67, 95, 98,...

    1. Given the array grade created as: int [] grade = {75, 80, 67, 95, 98, 88}; Fill in the following table with the required information.                                                      What is the value of  grade.length ? _________             What is the value of grade[1] ?        _________ 2. Write a get method (also known as a accessor method) for the hasNotPaid attribute.

  • Write Java statements that swap the element at the position given by the int variable index...

    Write Java statements that swap the element at the position given by the int variable index with the element that is two positions to its left in an array of char values called myChars. Use an if – else statement to make sure that this operation is possible (i.e. that all indexes are valid) and if not outputs a warning message.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT