All pastes #798400 Raw Edit

Miscellany

public java v1 · immutable
#798400 ·published 2007-11-26 20:02 UTC
rendered paste body
/** Class				oppgave1a* By				Rune Vikestad* E-Mail			vikestad@stud.ntnu.no* Web				http://folk.ntnu.no/vikestad/* Description		IT-1103, Basic Programming (Java), Exercise 6*/import java.io.*;import java.util.*;import javax.swing.JOptionPane;/*** Class: 'oppgave1b'*/public class oppgave1b {	/**	* Method: 'main'.	*/	public static void main(String[] args) throws IOException {		/*		* Variable Declarations		*/		FileReader fr;		FileWriter fw;		PrintWriter pw;		String fileInName;			// The name of the file we read from		String fileOutName;			// The name of the file we write to		int charCode;				// The decimal value of a character read		char wordPart;				// The alphanumeric value of a character read.		String wordTemp = "";		// The temporary string used to store words, before they're processed into an array.		int counter = 0;			// We use this integer to count how many words we've read, for the array.		String[] wordArray;			// Our words, in an array.		/*		* Variable Initiations		*/		fileInName = JOptionPane.showInputDialog("File name: ");		fileOutName = JOptionPane.showInputDialog("File name (Output): ");		fr = new FileReader(fileInName);		fw = new FileWriter(fileOutName);		wordArray = new String[100];		/*		* Process our stream.		*/		do {			charCode = fr.read();			/* If character isn't a Comma, Period, Space or EOF. */			if (charCode != 46 && charCode != 44 && charCode != 32 && charCode != -1) {				if (charCode >= 65 && charCode < 97) {					/* Found an upper case character, so make it lower case. */					charCode = charCode + 32;				}				/* Insert the character into our temporary word */				wordPart = (char)charCode;				wordTemp = wordTemp + wordPart;			}			if (charCode == 32) {				/* Found a space, think we've got a word. */				counter = counter+1;				System.out.println(wordTemp);				wordTemp = "";			} else if (charCode == -1) {				/* Hit EOF, print the last word. */				counter = counter+1;				System.out.println(wordTemp);				wordTemp = "";			}		} while (charCode > 0);		fr.close();		System.exit(0);	}}