/home/caleb/ASDV-Java/Semester 3/Assignments/lab5-recursion2_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab5/recursion2_calebfontenot/OccurancesOfChar.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package edu.slcc.asdv.caleb.lab5.recursion2_calebfontenot;

import java.util.Scanner;

/**
 *
 * @author caleb
 */
public class OccurancesOfChar {
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String s = input.nextLine();
        System.out.print("Enter a character: ");
        char ch =input.nextLine().charAt(0);
        int times = count(s, ch);
        System.out.println(ch + " appears " + times
        + (times > 1 ? " times " : " time ") + "in " + s);
    }
    public static int count(String str, char a) {
        int result = 0;
        if (str.length() > 0) {
            result = count(str.substring(1), a) +
                    (( str.charAt(0) == a) ? 1 : 0);
        }
        return result;
    }
}