Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Reads a file of lower case names, and writes a file of the
- names with the first letter of each name in uppercase.
- */
- import java.io.FileReader;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- import java.io.PrintWriter;
- public class UpcaseNames
- {
- public static void main(String[] args)
- throws FileNotFoundException
- {
- String inputFileName = "names.txt";
- String outputFileName = "upcaseNames.txt";
- FileReader fr = new FileReader(inputFileName);
- PrintWriter writer = new PrintWriter(outputFileName);
- try
- {
- boolean isFirst = true;
- while(true)
- {
- int ch = fr.read();
- if(ch == -1)
- break;
- else if((char)ch == ' ' || (char)ch == '\n')
- {
- isFirst = true;
- writer.write((char)ch);
- }
- else if(isFirst)
- {
- isFirst = false;
- writer.write(Character.toUpperCase((char)ch));
- }
- else
- writer.write((char)ch);
- }
- }
- catch(Exception e){}
- try
- {
- fr.close();
- writer.close();
- }
- catch(Exception e){}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement