我找不到代码使用大小写字母的方法,我只能找到一种方法让它运行一个或另一个...尝试了一段时间仍然没有管理,漂亮你看到的新人!提前致谢!
import java.util.*; public class LectureTimes { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System. in ); char letter; System.out.println("Enter your class and" + " you will recieve your lecture time"); do { letter = sc.next().charAt(0); } while (letter < 'a' || letter > 'd'); if (letter == 'A') { System.out.println("Your class is at 10:00"); } else { if (letter == 'a') { System.out.println("Your class is at 10:00"); } else { if (letter == 'B') { System.out.println("Your class is at 12:00"); } else { if (letter == 'b') { System.out.println("Your class is at 12:00"); } else { } if (letter == 'C') { System.out.println("Your class is at 14:00"); } else { if (letter == 'c') { System.out.println("Your class is at 14:00"); } else { System.out.println("Your group does not exist, please select one that does..."); } } } } } } }
kunruh.. 6
由于还没有人发布过交换机案例解决方案,这里是:
switch (letter) { case 'A': case 'a': System.out.println("Your class is at 10:00"); break; case 'B': case 'b': System.out.println("Your class is at 12:00"); break; case 'C': case 'c': System.out.println("Your class is at 14:00"); break; default: System.out.println("Your group does not exist, please select one that does..."); break; }
就个人而言,我发现这是最易读的解决方案.
由于还没有人发布过交换机案例解决方案,这里是:
switch (letter) { case 'A': case 'a': System.out.println("Your class is at 10:00"); break; case 'B': case 'b': System.out.println("Your class is at 12:00"); break; case 'C': case 'c': System.out.println("Your class is at 14:00"); break; default: System.out.println("Your group does not exist, please select one that does..."); break; }
就个人而言,我发现这是最易读的解决方案.