当前位置:  开发笔记 > 编程语言 > 正文

苦苦于在我的代码中使用大小写

如何解决《苦苦于在我的代码中使用大小写》经验,为你挑选了1个好方法。

我找不到代码使用大小写字母的方法,我只能找到一种方法让它运行一个或另一个...尝试了一段时间仍然没有管理,漂亮你看到的新人!提前致谢!

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

就个人而言,我发现这是最易读的解决方案.



1> kunruh..:

由于还没有人发布过交换机案例解决方案,这里是:

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

就个人而言,我发现这是最易读的解决方案.

推荐阅读
ar_wen2402851455
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有