这是我的代码:
public class Exercixe09_04 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a string: ");
String s1 = input.next();
System.out.println("Enter a character: ");
String s2 = input.next();
char c = s2.charAt(0);
int num = count(s1, c);
System.out.print(num);
}
public static int count(String str, char a)
{
int count = 0;
for(int i =0; i < str.length(); i++)
if(str.charAt(i) == 'a'){
count++;
}
return count;
}
}
当我编译并运行它时,什么也没有打印出来。有人可以帮我找出问题所在吗?