//提示是:编写一个程序,要求用户输入一个字符串,然后//让用户输入一个字符。程序应计数并显示指定字符在字符串中出现的次数。字母计数器代码
import java.util.Scanner;
public class LetterCounter{
Scanner keyboard = new Scanner (System.in); //Scanner
// Declare Variables
String userString; // String user entered
String userCharacter; // Character user entered
int StringSize;
// Ask the user to enter a string
System.out.println("Please Enter a String.");
userString = keyboard.nextLine();
// Ask the user to enter a charcter
System.out.println("Please Enter a Character.");
userCharacter = keyboard.nextLine();
// Count and display the number of times that character appears in the
// string chosen by the user.
int character;
character = Integer.parseInt(userCharacter);
StringSize = userString.charAt(character);
}
}
由于某种原因,我无法完成它的工作,我只是不知道该从哪里出发。我可能需要一个FOR-LOOP?
感谢您的帮助
您是否尝试过运行代码?我很确定它不会编译。 –