Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

help for a beginner in java on io stuff

807600Nov 4 2007 — edited Nov 4 2007
Hey I'm new here and I am currently learning java in school
I have a few questions?

one my teacher wants us to write a program that has you read a few words from a text file and output it in another file in title case form

so I wrote


public class Hw7
{
	public static void main(String args[])
							throws FileNotFoundException 
							
	{
		Scanner inFile = 
		new Scanner(new FileReader("Raw.txt"));
		PrintWriter outFile = new PrintWriter("processed.txt");
		String one;
		int words = 1;
		
		
		
		while (words < 20)
		{
		
		 one = inFile.next();
		 one = one.substring(0,1).toUpperCase() + one.substring(1).toLowerCase();
		 outFile.print(one);
		 words = words + 1;
		}
		inFile.close();
		outFile.close();
But apparently its not working.
there are only nine words in the text and I know I can make a seperate string for each one but that would be stupid.
Instead I wanted to use one string and repeat it until it got through all of them.
I was trying to be smart...
please help
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2007
Added on Nov 4 2007
6 comments
78 views