Question:
Rotate vowels in java..,, from a .txt file?
cool b
2009-04-20 06:35:03 UTC
Pls help me
following is my exercise to do

Exercise 2 - Rotate vowels
Copy a file named "history" to an output file named "history.copy" rotating the lower-case vowels. That is, change all occurrences of
'a' to 'e'
'e' to 'i'
'i' to 'o'
'o' to 'u'
'u' to 'a'

-----------------------------------------------------------------------------------------------------------------------------------------
Typical input file

In an age when acronyms were popular, the Manchester Mark I was sometimes referred to as MADM (Manchester Automatic Digital Machine) or MUC (Manchester University Computer).


-----------------------------------------------------------------------------------------------------------------------------------------
Typical output file

In en egi whin ecrunyms wiri pupaler, thi Menchistir Merk I wes
sumitomis rifirrid tu es MADM (Menchistir Aatumetoc Dogotel Mechoni) ur MUC (Menchistir Unovirsoty Cumpatir).

----------------------------------------------------------------------------------------------------------------------------------------
Three answers:
Trupti N
2009-04-21 04:47:09 UTC
Will need a bit of tweaking for case handling...and u can use any collection u want...i love hashmaps :)

Hope this helps



HashMap vowelMap = new HashMap();

vowelMap.put("a","e");

vowelMap.put("e","i");

vowelMap.put("i","o");

vowelMap.put("o","u");

vowelMap.put("u","a");



try{

File file = new File("C:\\Test.txt");

FileInputStream fis = new FileInputStream(file);

StringBuffer buf = new StringBuffer();

int n = 0;

while ((n = fis.read()) != -1){

char c = (char)n;

String s = Character.toString(c);

if(vowelMap.containsKey(s)){

buf.append(vowelMap.get(s));

}else{

buf.append(s);

}

}

System.out.println(buf.toString());

}catch(FileNotFoundException fnfe){

System.err.println("FileNotFoundException: " + fnfe.getMessage());

}catch(IOException ioe){

System.err.println("IOException: " + ioe.getMessage());

}

}
2017-01-20 16:53:38 UTC
if u attempt using the explorer report supervisor in homestead windows, merely be sure you have activated the alternative that makes it instruct the extension truly of hiding it, in any different case the sole element u are waiting to alter is the "physique" of the call and not the full report call
2009-04-21 04:39:21 UTC
didn't understand any question neither this nor the other one by u


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...