I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at my mobile number 09173084360.
Thank you very much and Happy Programming.
Sample Program Output
Program Listing
/* remove_consonants.java */
/* Written By: Mr. Jake R. Pomperada, MAED-IT */
/* July 14, 2015 */
/* This program will remove consonants in a given word or string by the user */
import java.util.Scanner;
class remove_consonants
{
private static String remove_Consonants(String s) {
String finalString = "";
for (int i = 0;i < s.length(); i++) {
if (!isConsonants(Character.toLowerCase(s.charAt(i)))) {
finalString = finalString + s.charAt(i);
}
}
return finalString;
}
private static boolean isConsonants(char c) {
String consonants = "bcdfghjklmnpqrstvwxyz";
for (int i=0; i<21; i++) {
if (c == consonants.charAt(i))
return true;
}
return false;
}
public static void main(String args[])
{
String words;
char ch;
do {
Scanner input = new Scanner(System.in);
System.out.println();
System.out.print("\t CONSONANTS REMOVER PROGRAM ");
System.out.println("\n");
System.out.print("Kindly enter a word :=> ");
words= input.nextLine();
System.out.println("The original words is " + words + ".");
String final_words = remove_Consonants(words);
System.out.println("The remaining letters is " + final_words + ".");
System.out.print("\nDo you want to continue (Type y or n) : ");
ch = input.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
System.out.println();
System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
System.out.println("\n\n");
}
}
No comments:
Post a Comment