Concept explainers
Explanation of Solution
a.
Given:
if x>0 then System.out.print(x)
Error #1:
There is no parenthesis around “x>0”. The “if” statement should be enclosed with “( )” around the condition...
Explanation of Solution
b.
Given:
if (1+x> Math.pow(x,Math.sqrt(2)){ y=y+x;}
Error #1:
In the given statem...
Explanation of Solution
c.
Given:
if (x=1){y++;}
Error #1:
In the given statement, there is only ...
Explanation of Solution
d.
Given:
//Get the integer value
x = in.nextInt();
//Check whether the value is integer
if (in.hasNextInt())
{
//Add the sum with x
sum = sum + x;
}
//Otherwise
else
{
//Print the output
System.out.println("Bad input for x");
}
Error #1:
In the code snipped statement, the programmer tries to validate the input. The “x=in.nextInt()” should be placed inside the “if” statement rather than placing it outside the “if” statement...
Explanation of Solution
e.
Given:
//Get the string value
String letterGrade = "F";
//Check the grade value is greater than or equal to 90 and assign "A"
if (grade >= 90) { letterGrade = "A"; }
//Check the grade value is greater than or equal to 80 and assign "B"
if (grade >= 80) { letterGrade = "B"; }
//Check the grade value is greater than or equal to 70 and assign "C"
if (grade >= 70) { letterGrade = "C"; }
//Check the grade value is greater than or equal to 60 and assign "D"
if (grade >= 60) { letterGrade = "D"; }
Error #1:
The given code snippet should be enclosed with “if else” statement rather than single “if” statement...
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Big Java, Binder Ready Version: Early Objects
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education