我确信这是一个简单的解决方法,但它让我头疼。为什么无法打印count
家庭作业,所以我不能改变太多。
package practice.stuff.here;
import java.util.Scanner;
/**
*
* @author Danan
*/
public class PracticeStuffHere {
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
System.out.println("Give me a saying you use");
String saying = input.nextLine();
System.out.println("The saying you gave me has the character a in it " );
System.out.println(count(saying, char a)); //////this is the issue im having
}
public static int count(String saying, char a) {
int countR = 0;
for(int i = 0; i <saying.length(); i++)
{
if(saying.charAt(i) == a)
countR++;
}
return countR;
}
}