import java.util.Scanner;????public class Example3 { ????????public static void main(String[] args) { ????????// TODO Auto-generated method stub???????? Scanner intup = new Scanner(System.in);???????? System.out.println("請輸入新員工姓名");???????? String a = intup.nextLine();???????? System.out.println("請輸入新員工應(yīng)聘的工作類型");???????? String b = intup.nextLine();???????????? switch (b.hashCode()) {???????????? case 22222:???????????? case 33333:???????????? case 44444:???????????????? System.out.println("請帶他去JAVA開發(fā)小組");???????????????? break;???????????? case 55555:???????????? case 66666:???????????? case 77777:???????????????? System.out.println("請帶他去C++開發(fā)小組");???????????????? break;???????????? case 88888:???????????? case 99999:???????????? case 00000:???????????????? System.out.println("請帶他去.NET開發(fā)小組");???????????????? break;???????????? default:???????????? ???? System.out.println("輸入錯(cuò)誤,請從新輸入!"); ????????} ????}}下面是運(yùn)行結(jié)果:請輸入新員工姓名張炎生請輸入新員工應(yīng)聘的工作類型22222輸入錯(cuò)誤,請從新輸入!請大神們指點(diǎn)迷津!小子在此謝過了。
3 回答
已采納

蒲公英wsg
TA貢獻(xiàn)242條經(jīng)驗(yàn) 獲得超126個(gè)贊
String b = intup.nextLine();
b是字符串,下面switch是int,能匹配成功嗎?
有三種方法
1、將下面的case條件改成字符串
2、將b改成整形
3、switch (Integer.valueOf(b))
望采納~~~~~~~~~~~~~~~~~~

Damon__huang
TA貢獻(xiàn)6條經(jīng)驗(yàn) 獲得超0個(gè)贊
一個(gè)字符串的hashcode值等于自身(在可以轉(zhuǎn)成int類型的情況下,轉(zhuǎn)化成int)的概率非常小吧
添加回答
舉報(bào)
0/150
提交
取消