In: Computer Science
Can you fix the errors in this code?
package demo;
/**
*
*
*/
import java.util.Scanner;
public class Booolean0p {
public class BooleanOp {
public static
void main(String[] args) {
int a = 0, b = 0 , c = 0;
Scanner kbd = new Scanner(System.in);
System.out.print("Input the first number:
");
a = kbd.nextInt();
System.out.print("Input the second number:
");
b = kbd.nextInt();
System.out.print("Input the third number:
");
System.out.println();
System.out.println("a = " + a + ", b = " + b + "
and c = " + c);
System.out.println();
System.out.println(a + " is greater than " + b +
": " + (a > b));
System.out.println(a + " is less than " + b + ":
" + " UNKNOWN");
System.out.println(a + " is equal to " + b + ":
" + " UNKNOWN");
System.out.println(a + " is greater or equal to
" + b + ": " + (a >= b));
System.out.println(a + " is less than or equal
to " + b + ": " + " UNKNOWN");
System.out.println(a + " is not equal to " + b +
": " + (a != b));
System.out.println(a + " is greater than " + b +
" OR " + a + " is equal to " + c + ": " + (a > b || a ==
c));
System.out.println(a + " is less than " + b + "
OR " + a + " is equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is equal to " + b + "
OR " + a + " is equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is greater or equal to
" + b + " AND " + a + " is equal to " + c + ": " + "
UNKNOWN");
System.out.println(a + " is less than or equal
to " + b + " AND " + a + " is equal to " + c + ": " + "
UNKNOWN");
System.out.println(a + " is not equal to " + b +
" AND " + a + " is equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + "
OR " + a + " is greater than " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + "
OR " + a + " is less than " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + "
OR " + a + " is equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + "
AND " + a + " is greater or equal to " + c + ": " + "
UNKNOWN");
System.out.println(a + " is less than " + b + "
AND " + a + " is less than or equal to " + c + ": " + "
UNKNOWN");
System.out.println(a + " is less than " + b + "
AND " + a + " is not equal to " + c + ": " + (a < b && a
!= c));
kbd.close();
}
}
}
}
Program:
Explanation:
Line 1: //Header file for scanner object
Line 2: //Here taking class name as Booolean0p
Line 3: //Start of main()
Line 4: //Here initializing the values of integer variables called
a,b,c
Line 5:// Here creating the scanner object called kbd
Line 6://Here asking the user to enter first number
Line 7://Here scanning the user input for a
Line 8://Here asking the user to enter second number
Line 9://Here scanning the user input for b
Line 10://Here asking the user to enter third number
Line 11://Here scanning the user input for c
Line 12://printing the statement
Line 13://Here printing the values of a , b, c
Line 14: //printing the statement
Line 15://Checking the condition and pritning
Line 16://Checking the condition and pritning
Line 17://Checking the condition and pritning
Line 18://Checking the condition and pritning
Line 19://Checking the condition and pritning
Line 20:// Checking the condition and pritning
Line 21: //Checking the condition and pritning
Line 22: //Checking the condition and pritning
Line 23: //Checking the condition and pritning
Line 24: //Checking the condition and pritning
Line 25: //Checking the condition and pritning
Line 26: //Checking the condition and pritning
Line 27: //Checking the condition and pritning
Line 28: //Checking the condition and pritning
Line 29: //Checking the condition and pritning
Line 30: //Checking the condition and pritning
Line 31: //Checking the condition and pritning
Line 32: //Checking the condition and pritning
Line 33: //Checking the condition and pritning
Line 34: //Checking the condition and pritning
Line 35: //End of main()
Line 36://End of class Booolean0p
Program:
import java.util.Scanner;
class Booolean0p {
public static void main(String[] args) {
int a = 0, b = 0 , c = 0;
Scanner kbd = new Scanner(System.in);
System.out.print("Input the first number: ");
a = kbd.nextInt();
System.out.print("Input the second number: ");
b = kbd.nextInt();
System.out.print("Input the third number: ");
c = kbd.nextInt();
System.out.println();
System.out.println("a = " + a + ", b = " + b + " and c = " + c);
System.out.println();
System.out.println(a + " is greater than " + b + ": " + (a >
b));
System.out.println(a + " is less than " + b + ": " + "
UNKNOWN");
System.out.println(a + " is equal to " + b + ": " + "
UNKNOWN");
System.out.println(a + " is greater or equal to " + b + ": " + (a
>= b));
System.out.println(a + " is less than or equal to " + b + ": " + "
UNKNOWN");
System.out.println(a + " is not equal to " + b + ": " + (a !=
b));
System.out.println(a + " is greater than " + b + " OR " + a + " is
equal to " + c + ": " + (a > b || a == c));
System.out.println(a + " is less than " + b + " OR " + a + " is
equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is equal to " + b + " OR " + a + " is
equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is greater or equal to " + b + " AND " + a
+ " is equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than or equal to " + b + " AND " +
a + " is equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is not equal to " + b + " AND " + a + " is
equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + " OR " + a + " is
greater than " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + " OR " + a + " is
less than " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + " OR " + a + " is
equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + " AND " + a + " is
greater or equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + " AND " + a + " is
less than or equal to " + c + ": " + " UNKNOWN");
System.out.println(a + " is less than " + b + " AND " + a + " is
not equal to " + c + ": " + (a < b && a != c));
kbd.close();
}
}
Output: