The following code should print X is greater than 0. However, the code has errors. Fix the code so that it compiles and runs correctly. (Rewrite the program with all the fixes)
public class Test1
{
public static void main(String[] args)
{
int x = 3;
if (x > 0
System.out.println("x is greater than 0")
else
System.out.println(x is less than or equal 0");
}
}
Must be in java and easy to understand grade 11 course
SOLUTION
Here is the compiler errors that you will get if you you try to run the above code:
Lets fix those issues.
Here is the corrected code with comments to help you understand the errors and the fixes.
public class Test1
{
public static void main(String[] args){
int x = 3;
//in the bottom line there was a closing bracket missing ")" . Adding that
if (x > 0)
//in the below line there was a semi-colon missing at the end of the statement. Adding that
System.out.println("x is greater than 0");
else
//In the below line there was a starting double quote missing
System.out.println("x is less than or equal 0");
}
}
_____________________________________________________________________________________________
Example run:
Get Answers For Free
Most questions answered within 1 hours.