Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will write a program where you ask the user to enter an ‘A’ or ‘a’, ‘B’ or ‘

ID: 3793746 • Letter: Y

Question

You will write a program where you ask the user to enter an ‘A’ or ‘a’, ‘B’ or ‘b’, or ‘C’ or ‘c’. If they enter an uppercase or lowercase ‘A’ you will print out ‘A is for apple’, for an uppercase or lowercase ‘B’ you will print out ‘B is for balloon’, for an uppercase or lowercase ‘C’ you will enter ‘C is for cat’, otherwise you will print out ‘I don’t recognize the character’. When writing this program you will use an if/else if condition and the || (or) logical connector.

This is all done in java oracle. Right now this is my following code:

import java.util.Scanner;
public class Lab4 {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       String strInput = "";
       char chInput = '';
       Scanner scan = new Scanner(System.in);
       System.out.println("Please enter A, a, B, b, C, or c.");
       strInput = scan.nextLine();
       chInput = strInput.charAt(0);  
      
   if (chInput = A||a);{
       System.out.println("A is for apples");
   }
   else if (chInput = B||b);{
       System.out.println("B is for balloon");
   }
   else if (chInput = C||c);{
       System.out.println("C is for cat");
   }
   else;
   System.out.println("I don't recongniz this character);
   }
   }

I'm getting a couple compiling errors and don't know how to fix it.

Explanation / Answer

Hi,

I have modified the code and hghlighted the code changes. it is working fine now.

Lab4.java
import java.util.Scanner;
public class Lab4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String strInput = "";
char chInput = '';
Scanner scan = new Scanner(System.in);
System.out.println("Please enter A, a, B, b, C, or c.");
strInput = scan.nextLine();
chInput = strInput.charAt(0);
  
if (chInput == 'A' ||chInput == 'a'){
System.out.println("A is for apples");
}
else if (chInput == 'B' ||chInput == 'b'){
System.out.println("B is for balloon");
}
else if (chInput == 'C' ||chInput == 'c'){
System.out.println("C is for cat");
}
else{
System.out.println("I don't recongniz this character");
}
}
}

Output:

Please enter A, a, B, b, C, or c.
b
B is for balloon

Please enter A, a, B, b, C, or c.
c
C is for cat

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote