Java switch statement
Go to solution
Solved by kwljunky,
snip
Character.toLowerCase()
Or Character.toUpperCase() ?
Here is the details of the Character class in the java doc: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html
so:
/** * Write a description of class Practice here. * * @author (your name) * @[member='versions'] (a version number or a date) */import java.util.Scanner;public class Practice{ public static void main(String[]args) { Scanner scan = new Scanner(System.in); char letter; System.out.print("enter a letter you idiot"); letter = scan.next().charAt(0); myABCs(letter); } public static void myABCs(char letter) { letter = Character.toLowerCase(letter); //before the switch statement as the char is passed into the method switch(letter) { case 'a': System.out.print("apple"); break; case 'b': System.out.print("batt"); break; case 'c': System.out.print("cat"); break; } } }

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now