【发布时间】:2017-02-10 02:11:55
【问题描述】:
假设我们有一堆字符:'s', 'w', 'e', 's', 't', 'h'
我们如何查看我们是否通过(char)scanner.nextLine().charAt(0); 输入了一个字符
数字是(1,2,3,4,5,6)的位置。例如,如果我输入w,我会返回2,或者如果我输入s,我会返回1 和4。
这是我已有的代码:
Scanner letter= new Scanner(System.in);
System.out.print("Type a character:");
char let= letter.nextLine().charAt(0);
char[] word = {'s', 'w', 'a', 'g', 'w' };
System.out.print();
【问题讨论】:
-
为什么不用
String word="swagw"而不是Char Array。 -
老师说我们需要用char