program to remove vowels from a user input and diplay the remaining alphabets in alphabetic order in java -
please help me total code modified again. have tried, error coming stringindexoutofboundsexception
. able come in input user.
import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; public class removevowels{ public static void main(string []args) { bufferedreader in = new bufferedreader(new inputstreamreader(system.in)); system.out.println("sample programme remove vowels"); system.out.println("from given string \n"); system.out.println("enter words : "); string s = in.readline(); system.out.println("\n" + "string vowels removed : "); string r = removevowels(s); system.out.println(r); } private static string removevowels(string s) { string finalstring = ""; for(int = 0; < s.length(); i++) { if(!isvowel(character.tolowercase(s.charat(i)))) { finalstring = finalstring + s.charat(i); } } homecoming finalstring; } private static boolean isvowel(char c) { string vowels = "aeiou"; for(int = 0; < 5; i++) { if(c == vowels.charat(i)) homecoming true; } homecoming false; } }
add throws declaration method:
public static void main(string []args) throws ioexception
or surround code try/catch:
try { s = in.readline(); } grab (ioexception e) { e.printstacktrace(); }
you haven't included in code sort string alphabetically, can follows:
private static string ascending(string s) { char[] asc = s.tochararray(); arrays.sort(asc); string sorted = new string(asc); homecoming sorted; }
complete code:
import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import java.util.arrays; public class removevowels{ public static void main(string []args) throws ioexception { bufferedreader in=new bufferedreader(new inputstreamreader(system.in)); system.out.println("sample programme remove vowels given string \n"); system.out.println("enter line : "); string s=in.readline(); system.out.println("\n" + "string vowels removed : "); string r=removevowels(s); system.out.println(r); } private static string removevowels(string s) { string finalstring=""; for(int i=0;i<s.length(); i++) { if(!isvowel(character.tolowercase(s.charat(i)))) { finalstring=finalstring+s.charat(i); } } finalstring= ascending(finalstring); homecoming finalstring; } private static string ascending(string s) { char[] asc = s.tochararray(); arrays.sort(asc); string sorted = new string(asc); homecoming sorted; } private static boolean isvowel(char c) { string vowels="aeiou"; for(int i=0; i<5; i++) { if(c==vowels.charat(i)) homecoming true; } homecoming false; } }
java
No comments:
Post a Comment