我刚开始使用 Java,我正在玩。
我有以下代码,我想计算输入的字母“e”,但每次的输出都是“0”。我究竟做错了什么?谢谢。
import javax.swing.JOptionPane;
public class JavaApplication6 {
public static void main(String[] args, int z) {
int y,z = 0;
String food;
food = JOptionPane.showInputDialog("Are you curious how many \"e\"s there are in your favorite Food? Then Type your favorite food and I will tell you!");
char letter = 'e';
for(int x = 0; x < food.length();x++){
if(food.charAt(z)== letter){
y = y++;
}
}
JOptionPane.showMessageDialog(null, "it has: " + y);
}
}