我遇到了一些java代碼的問題,所以我想我會在這裏問它。我被要求添加一行代碼來照顧小寫輸入,但我不確定如何實現它。我可能大大過於尋找一個非常簡單的修復,但任何幫助,非常感謝。如何正確使用toUpperCase();
import java.util.Scanner;
public class Worksheet_7
{
public static void main(String[]args)
{
Scanner Fred = new Scanner(System.in);
System.out.println("Today we practice using switch statements \n\n");
char Ans;
System.out.println("What kind of car do you drive");
System.out.println("(F)ord, (C)hevy, (B)uick,(M)azda,(H)onda");
String Word = Fred.next();
Ans=Word.charAt(0);
switch(Ans)
{
case 'C': System.out.println("Chevy-the heartbeat of America");
System.out.println("Buy a ford");
break;
case 'F': System.out.println("Ford tough");
System.out.println("Nice job cowboy");
break;
case 'B': System.out.println("Buick-Luxury you can afford");
System.out.println("Seriously? A Buick? That's not Luxury");
break;
case 'M': System.out.println("Mazda-Zoom, Zoom");
System.out.println("Can't really say anything");
break;
case 'H': System.out.println("Honda-Always dependable");
System.out.println("Yeah, yeah, yeah");
break;
default: System.out.println("Need a better car...?");
}
System.out.println("\n\n done for now..");
}
}
你需要改變你比較'Ans'的情況下,也許從那裏開始 – MadProgrammer