java - 在字符串中使用 switch

标签 java switch-statement

尝试在字符串中使用 switch,首先将字符串转换为 char,然后应用 switch,但仍然没有完成......这是我的代码......

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.swing.JOptionPane;

class HappyBirthday {

    public static void main(String[] args) throws IOException {
        String Month;
        char[] Months = Month.toCharArray();
        BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please enter your month.");

        Month = JOptionPane.showInputDialog("enter month");
        String month1 = { "January", "feb"};
        char[] month2 = month1.toCharArray();

        // String s=month1.equals(Month);
        // System.out.print(month2Array[0]);
        switch (month2) {

        case 0:
            System.out.println("kool");
            break;

        case 1:
            System.out.println("not kool");
            break;
        default:
        }
    }
}
/**
 * if (month1[1].equals(Month)) System.out.println("kool"); else
 * if(month1[0].equals(Month)) System.out.println("kooooooooooooool"); else
 * System.out.println("Big kooooool");
 **/

最佳答案

看看这个 excellent article就这个主题而言。

关于java - 在字符串中使用 switch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2934566/

相关文章:

c - 为什么我们甚至不允许在 switch-case 中使用全局 const 限定变量?IBM 支持门户提示我们可以

java - Maven 3.5.0 抛出 ArrayIndexOutOfBoundsException,但使用 Maven 3.3.9 构建

java - 使用 JSON 迭代器输入安全警告

java - 执行阶段持续 2 分钟,在此期间客户将在 2 - 6 秒之间随机到达并被放入队列中

ios - Swift iOS - 如何从 AVPlayerItemStatus 访问错误?

c# - asp.net mvc Controller 中的封装开关逻辑

Ruby 删除 Case 语句中的隐式中断? (如何制作像 Switch 一样的外壳)

java - 在依赖于我自己的 Maven Artifact 的 Heroku 上部署 Java 应用程序

java - 为什么使用整数而不是 double ?

swift - Swift 中的奇怪行为 switch-case 语句