In the following code, correct any errors that would prevent the program from co
ID: 3597021 • Letter: I
Question
In the following code, correct any errors that would prevent the program from compiling or running:
public class Errors
{
public static void main (String[] args)
{
int a, b;
boolean found;
System.out.print ("Enter the first interger: ");
a = console.nextInt();;
System.out.print1n();
System.out.print("Enter the second integer:");
b = console.nextInt();;
if a > a * b && 10 < b
found = 2 * a > b;
if found
a =3;
c=15;
if b
{
b = 0;
a = 1;
}
}
}
}
Please make copy paste available
Explanation / Answer
Removed errors,now check and add appropriate print statements
**Code:
import java.util.Scanner;
public class Errors
{
public static void main (String[] args)
{
int a, b;
boolean found = false;
// Add the scanner for getting input
Scanner console = new Scanner(System.in);
System.out.print ("Enter the first interger: ");
// One semicolon not two
a = console.nextInt();
// It is println not print1n
System.out.println();
System.out.print("Enter the second integer:");
//One semicolon not two
b = console.nextInt();
// Convert with brackets if statements
if (a > a * b && 10 < b)
found = 2 * a > b;
// Surround with brackets for if case block
if (found){
a =3;
int c = 15;
}
if (b > 0)
{
b = 0;
a = 1;
}
System.out.println("a = " + a + " b = " + b + " found = " + found);
}
}
**Comment for any further queries.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.