在字符串中使用switch [英] using switch in strings
本文介绍了在字符串中使用switch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试在字符串中使用switch,首先将字符串转换为char然后应用switch但仍然没有完成它....这是我的代码..
Trying to use switch in strings by first coverting string into char and then apply switch but still didnt done it....here is my code..
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");
**/
推荐答案
看看关于此主题的优秀文章。
这篇关于在字符串中使用switch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文