有不等于char的地方吗 [英] is there a not equals for char
本文介绍了有不等于char的地方吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将其添加到此代码中
I''m trying to add it to this code
char input;
String state = in.next();
input = state.charAt(0);
do
{
System.out.println("Please enter a command type:");
}while(!input);
推荐答案
没有,没有.但是,如果字符串input
为空,则charAt
方法将引发IndexOutOfBoundsException
(请参见 ^ ]).
您想做什么?
Nope, there is not. However, if the stringinput
is empty then thecharAt
method throws theIndexOutOfBoundsException
(see the documentation[^]).
What are you trying to do?
尝试这个
Scanner in=new Scanner(System.in);
char ch ;
do{
System.out.println("Enter the a character");
try{
ch= in.nextLine().charAt(0);
System.out.println("Char: "+ch);
}
catch (IndexOutOfBoundsException e) {
ch = 'z';
}
}while(ch < 'a' || ch > 'g');
这篇关于有不等于char的地方吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文