- package text;
- import java.util.Scanner;
- public class JPA04 {
- static Scanner keyboard = new Scanner(System.in);
- public static void main(String args[]) {
-
- System.out.print("Input a string: ");
- String num=keyboard.nextLine();
-
- System.out.print(num+"has"+countA(num)+"As");
-
- }
-
- public static int countA(String str) {
-
- if(str.equals(""))
- {
- return 0;
- }
- else if(str.substring(0,1).equals("A"))
- {
- return 1+countA(str.substring(1));
- }
- else
- {
- return countA(str.substring(1));
- }
- }
- }
複製代碼 |