oldinput是字符串,newinput。charAt得到的是字符,所以不能比较。我猜测是这样。
解决方案 »
- 新手求助下Java连接MySQL的问题
- try....catch...finally
- 为什么编译运行后,点击“录入”会出现异常?请问异常在哪里?
- replace的问题
- mysql+hibernate一个超级简单的例子出现问提?帮忙解决一下!
- 关于java socke的问题
- 一个关于Japplet在html中显示的问题?
- java连接数据库的问题,闷啊,Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
- 求助!java程序怎么算两时间段的月份差
- 一道面试题,已到锅里,
- upcasting的含义及其作用是什么?
- keyReleased不同步
也不行啊
字符串怎么能和char比较呢
这样就把newinput.charAt(i)传成String
这样就能比较了
而你前面是一个String对象,肯定不能比较啊
oldinput == String.valueOf(newinput.charAt(i))或者
oldinput == String.toString(newinput.charAt(i))试试
public class test{
public static void main(String agrs[]){
int x;
int y=0; String input = JOptionPane.showInputDialog("Enter a word, please");
String input1 = JOptionPane.showInputDialog("Enter a letter, please"); String newinput = input.toLowerCase();
String oldinput = input1.toLowerCase(); int A = newinput.length();
for(int i=0; i<A; i++){
if(oldinput == String.valueOf(newinput.charAt(i))){
x=1;
y=y+x;} } JOptionPane.showMessageDialog(null,input1+"apears"+y+"times in this word"+input);
}
}