Last active
November 7, 2023 05:06
-
-
Save rafirh/3272fd42c61790a8b93d89d18c26de79 to your computer and use it in GitHub Desktop.
Hitung Jumlah Huruf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
String kalimat = scanner.nextLine(); | |
char huruf = scanner.next().charAt(0); | |
int jumlahHuruf = hitungJumlahHuruf(kalimat, huruf); | |
System.out.println("Huruf " + huruf + " pada kata " + kalimat + " ada " + jumlahHuruf); | |
scanner.close(); | |
} | |
public static int hitungJumlahHuruf(String kalimat, char huruf) { | |
kalimat = kalimat.toLowerCase(); | |
huruf = Character.toLowerCase(huruf); | |
String kalimatTanpaHuruf = kalimat.replace(String.valueOf(huruf), ""); | |
int jumlahHuruf = kalimat.length() - kalimatTanpaHuruf.length(); | |
return jumlahHuruf; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment