Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Count X
- Given a string, compute recursively (no loops) the number of lowercase 'x' chars in the string.
- Input
- On the first line you will be given a string
- Output
- On the only output line you should print the number of lowercase x in it.
- Sample tests
- Input
- xxhixx
- Output
- 4
- Input
- xhixhix
- Output
- 3
- import java.util.Scanner;
- public class Input {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- System.out.println(lowerCase(input, 'x'));
- }
- public static int lowerCase(String input, char ch){
- int counter = 0;
- if(input.length()>0){
- if(Character.isLowerCase(input.charAt(0)) && input.charAt(0) == ch){
- counter++;
- }
- counter+=lowerCase(input.substring(1), ch);
- }
- return counter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment