Question

In: Computer Science

Can you fix the errors in this code? package demo; /** * * */ import java.util.Scanner;...

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();
           }
       }
   }

}

Solutions

Expert Solution

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:


Related Solutions

Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public static void main(String[] args) {        System.out.println("This program will ask the user for three sets of two numbers and will calculate the average of each set.");        Scanner input = new Scanner(System.in);        int n1, n2;        System.out.print("Please enter the first number: ");        n1 = input.nextInt();        System.out.print("Please enter the second number: ");        n2 =...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public class CourseeCOM616 {        private String courseName;     private String[] studentsName = new String[1];     private String studentId;        private int numberOfStudents;        public CourseeCOM616(String courseName) {         this.courseName = courseName;     }     public String[] getStudentsName() {         return studentsName;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getStudentId() {         return studentId;    ...
Please fix all of the errors in this Python Code. import math """ A collection of...
Please fix all of the errors in this Python Code. import math """ A collection of methods for dealing with triangles specified by the length of three sides (a, b, c) If the sides cannot form a triangle,then return None for the value """ ## @TODO - add the errlog method and use wolf fencing to identify the errors in this code def validate_triangle(sides): """ This method should return True if and only if the sides form a valid triangle...
In Java please Cipher.java: /* * Fix me */ import java.util.Scanner; import java.io.PrintWriter; import java.io.File; import...
In Java please Cipher.java: /* * Fix me */ import java.util.Scanner; import java.io.PrintWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; public class Cipher { public static final int NUM_LETTERS = 26; public static final int ENCODE = 1; public static final int DECODE = 2; public static void main(String[] args) /* FIX ME */ throws Exception { // letters String alphabet = "abcdefghijklmnopqrstuvwxyz"; // Check args length, if error, print usage message and exit if (args.length != 3) { System.out.println("Usage:\n"); System.out.println("java...
----fix code to search and delete a student by Identification number import java.util.Scanner; public class COurseCom666...
----fix code to search and delete a student by Identification number import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public int DeleteStudentsByID() {         return...
I wrote this code and it produces a typeError, so please can you fix it? import...
I wrote this code and it produces a typeError, so please can you fix it? import random def first_to_a_word(): print("###### First to a Word ######") print("Instructions:") print("You will take turns choosing letters one at a time until a word is formed.") print("After each letter is chosen you will have a chance to confirm whether or not a word has been formed.") print("When a word is formed, the player who played the last letter wins!") print("One of you has been chosen...
What is wrong with this code and how can it be fixed? import java.util.Scanner; public class...
What is wrong with this code and how can it be fixed? import java.util.Scanner; public class admissionRequirement { public static void main(String[] args) { // TODO Auto-generated method stub Scanner myObj = new Scanner(System.in); System.out.println("What is your name?"); String name = myObj.nextLine(); System.out.println("What is your Reading Score?"); int reading = myObj.nextInt(); System.out.println("What is your Math Score?"); int math = myObj.nextInt(); System.out.println("What is your Writing Score?"); int writing = myObj.nextInt(); System.out.println("What is your Class Standing?"); int standing = myObj.nextInt(); System.out.println("What is...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T,...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T, size> extends Throwable { private final T[] S = null ; public StackException(String s) { } public T top() throws StackException { if (isEmpty()) throw new StackException("Stack is empty."); int top = 0; return S[top]; } private boolean isEmpty() { return false; } public T pop() throws StackException { T item; if (isEmpty()) throw new StackException("Stack underflow."); int top = 0; item = S[top];...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner;...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public void...
Can someone fix this code so that it can count comparison and exchange? import java.util.Arrays; class...
Can someone fix this code so that it can count comparison and exchange? import java.util.Arrays; class Main { static int comparisons; static int exchanges; // Recursive function to perform insertion sort on sub-array arr[i..n] public static void insertionSort(int[] arr, int i, int n) { int value = arr[i]; int j = i; // Find index j within the sorted subset arr[0..i-1] // where element arr[i] belongs while (j > 0 && arr[j - 1] > value) { arr[j] = arr[j...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT