Question

R3.3 Find the errors in each of the following if statements. a. if x 〉 e then System.out.print(x); b, if (1 + x > Math . pow(x, Math.sqrt(2)) { y = y + x; c.if(x=1) { y++; } d. x = in·nextInt(); if (in.hasNextInt()) sum = sum + x; else System.out.println(Bad input for x); e. String letterGrade = F; if (grade 〉= 90) { letterGrade _ A; } if (grade 〉= 80) { letterGrade- B; } if (grade 〉= 70) { letterGrade- C; } if (grade 〉= 60) { letterGrade- D; }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a)
there should be parenthesis for if Statement
if(x>0) is correct
b)
there should be closing parenthesis for if Statement.
if(1+x>Math.pow(x,Math.sqrt(2))) {y=y+x;} is correct

c)
x=1 is assignment, if Statement accepts only boolean.
if(x==1){y++;} is correct

d)
if Statement is checking next integer input which insted should check on x.
correct statement:
if(x){
sum =sum+x;
}
else{
System.out.println("Bad input for x");
}

e)

All for if statmets will be executed each time. suppose grade is 90
90>=90 satisfies.
90 >= 80 also satisfies
90 >= 70 also satisfies
90 >= 60 also satisfies
which produces the letterGrade as D which instead should be A. so to correct this use else if for the last three.

Add a comment
Know the answer?
Add Answer to:
R3.3 Find the errors in each of the following if statements. a. if x 〉 e...
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
  • 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...

  • please help me with this problem The following program uses if-else-if statements to determine a letter...

    please help me with this problem The following program uses if-else-if statements to determine a letter grade. Rewrite it using if statements with logical operators (&&, ||, !) to produce the same output when given the same inputs. import java.util.Scanner; public class GradeCalculator{ public static void main(String[] args){ int grade; Scanner input = new Scanner(System.in); System.out.println("Enter numeric grade out of 100: "); grade = input.nextInt(); if (grade >= 90){ System.out.println("Congratulations! You got an A!"); } else if (grade >= 80){...

  • Java Programming Language Edit and modify from the given code Perform the exact same logic, except...

    Java Programming Language Edit and modify from the given code Perform the exact same logic, except . . . The numeric ranges and corresponding letter grade will be stored in a file. Need error checking for: Being able to open the text file. The data makes sense: 1 text line of data would be 100 = A. Read in all of the numeric grades and letter grades and stored them into an array or arraylist. Then do the same logic....

  • Below is a java program that inputs an integer grade and turns it into a letter...

    Below is a java program that inputs an integer grade and turns it into a letter grade. Update the below java code as follows and comment each line to explain what is happening: 1. Convert the if-else-if code block to a switch statement to solve the problem. 2. Use modulus to convert the grade input so that the range of grades are converted to one value. (comment the line) import java.util.Scanner; public class GradeLetterTest { public static void main(String[] args)...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

  • Question 41 Which of the following is NOT a valid assignment statement? A. x = 55;...

    Question 41 Which of the following is NOT a valid assignment statement? A. x = 55; B. 55 = x; C. x += 3; D. x = 56 + y; Question 42 What is the result of 45 / 4? A. 11.25 B. 10 C. 12 D. 11 Question 43 What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0");...

  • What is the value of GPA when grade is 'B' in the following code segment? int...

    What is the value of GPA when grade is 'B' in the following code segment? int GPA=0; switch (grade) { case 'A': case 'a': GPA = GPA + 1; case 'B': case 'b': GPA = GPA + 1; case 'C': case 'c': GPA = GPA + 1; case 'D': case 'd': GPA = GPA + 1; } 4 3 2 1 None of the above #2.   Branching - switch statements... Extra info/hint? It's free What is the value of GPA when...

  • Consider the following statements. If the input is 95, the output of the following code will...

    Consider the following statements. If the input is 95, the output of the following code will be: #include <iostream> #include <string> using namespace std; int main ) { float score; string grade; cin >> score; grade - "Unknown"; if (score >= 90) grade - "A"; if (score > 80) grade - "B"; if (score > 70) grade - "C"; else grade - "F"; cout << grade; }

  • Page 1 of 6 Note: It is recommended that you save your response as you complete...

    Page 1 of 6 Note: It is recommended that you save your response as you complete each question. Question 1 (1 point) Correctly order the following lines of pseudocode to create a working algorithm Else Set grade = "F" 2 3 4 5 6 End If Else If score >= 60 Then Set grade = "D" Else If score >= 70 Then Set grade = "C" If score >= 90 Then Set grade = "A" Else If score >= 80...

  • HINT 1)-Write a method to accept n integer number between 0 and 100 and return the...

    HINT 1)-Write a method to accept n integer number between 0 and 100 and return the average. 2)-Write a method to convert an the letter grade as follow. integer number between 0 and 100 to latter grade A to F and return. 100-90->A 89-80->B 79-70->C 69-60->D 00-59->F 3)-Write a method to compute GPA for following letter grade and return the GPA value. A =>4.0 B ->3.0 C->20 D->1.0 Hint for option 1 1 import java.util.Scanner 2 public class ProjPart2 3...

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