我正在从用户那里获取字符串中的输入,我想使用 case 语句进行迭代和测试,但它不起作用。它不打印报表。
import java.io.*;
import java.util.*;
public class fh3
{
public static void main(String args[])throws IOException
{
String sentence = "";
System.out.println("Enter the word : ");
Scanner scan = new Scanner(System.in);
String word = scan.next();
char[] chars = word.toCharArray();
for(int i = 0; i < word.length(); i++)
{
System.out.println("---" + chars[i]);
switch(chars[i])
{
case 0: sentence = " ";
System.out.println("B");
break;
case 1: sentence = "A";
break;
case 2: sentence = "B";
System.out.println("B");
break;
case 3: sentence = "C";
break;
}
sentence+=sentence;
System.out.println(sentence);
}
}
}
如果我输入 20 den 它应该打印“B”但它的打印为
Enter the word :
20
---2
---0
我哪里错了?