i'm learning java , tasked reading in file, reversing each word in file (so "this file" output "siht elif"). have code here getting filenotfoundexception on compile file in proper location. because can't find file, can't see output @ point, although know not correct right now. can provide insight given have? methods used (and parameters passed in) required code within methods own , subject change. appreciated.
code:
import java.io.bufferedreader; import java.io.filenotfoundexception; import java.io.filereader; import java.io.ioexception; public class prog1 { public static void main(string[] args) throws filenotfoundexception, ioexception { bufferedreader in = new bufferedreader (new filereader("testfile.txt")); string line = in.readline(); in.close(); } private static string[] getwords(string line){ string[] wordlist = line.split("\\s+"); return wordlist; } private static void reversewords(string[] wordlist){ char[] words = new char [] char[] words = wordlist.tochararray(); string word = string.valueof(words); } private static string reverse (string word){ if (word.length()==0) return ""; else return (reverse(word)+ word.charat(0)); } private static void printwords(string[] wordlist){ string reversedlist = string.valueof(wordlist); system.out.print(reversedlist); } }
i assume on mac? check make sure permissions set on file correctly , make sure in same folder src file. lastly, make sure spellings correct.
Forums Macs Mac Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment