Created
October 22, 2014 03:41
-
-
Save erikgunawan/b1c909e69940302680a1 to your computer and use it in GitHub Desktop.
Menghitung Jumlah Huruf Vokal dan Konsonan dalam String dengan Java
This file contains 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.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
/** | |
* @Developer : Erik Gunawan | |
* @Nickname : EXz | |
* @Phone : 0896 5332 0577 | |
* @EMail : admin@erikgunawan.com | |
* @Gmail : erik.gunawan44@gmail.com | |
* @Website : www.erikgunawan.com | |
* @Facebook : facebook.com/revolutionist.exz | |
* @Twitter : twitter.com/_EXz | |
*/ | |
public class VokalKonsonan { | |
public static void main(String[] args) { | |
try { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
System.out.print("Masukkan text : "); | |
String x = br.readLine(); | |
System.out.println(); | |
int v = 0, c = 0; | |
for (int i=0; i<x.length(); i++) { | |
if (checkVC(x.charAt(i))==true) { | |
if (getVC(x.charAt(i))==1) | |
v++; | |
else | |
c++; | |
} | |
} | |
System.out.println("Jumlah huruf vokal : " + v); | |
System.out.println("Jumlah huruf konsonan : " + c); | |
System.out.println("Total huruf : " + (v+c)); | |
} | |
catch (IOException ioe) { | |
System.out.println("Error IOException : " + ioe.getMessage()); | |
} | |
} | |
private static boolean checkVC(char text) { | |
if ((text>=65 && text<=90) || (text>=97 && text<=122)) | |
return true; | |
else | |
return false; | |
} | |
private static int getVC(char text) { | |
int vc; | |
if (text=='A' || text=='E' || text=='I' || text=='O' || text=='U' | |
|| text=='a' || text=='e' || text=='i' || text=='o' || text=='u') | |
vc = 1; | |
else | |
vc = 0; | |
return vc; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment