Intro to CS student here.
I've been struggling to find a solution after spending a lot of time reading my text book and reviewing my professors slides.
Basically my program needs to read from an input file and make corrections, one of the corrections must be capitalizing all individual lowercase "i"s and outputting the corrected file.
I have the input/output part taken care of but now I'm just plain stuck.
import java.io.*;
import java.util.*;
public class WP {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(new File(args[0])); // first argument is input filename
PrintStream output = new PrintStream(new File(args[1])); // second arg is output filename
stripSpaces(input, output);
capCorrection(input, output);
}
static void stripSpaces(Scanner input, PrintStream output) {
String text = "";
while (input.hasNextLine()) {
text += input.nextLine() + "\n";
}
final int State_INIT = 0;
final int State_SEEN_SPACE = 1;
int state = State_INIT;
for (char c : text.toCharArray()) {
if (state == State_INIT) {
if (c == ' ') {
output.print(c);
state = State_SEEN_SPACE;
} else {
output.print(c);
}
} else if (state == State_SEEN_SPACE) {
if (c != ' ') {
output.print(c);
state = State_INIT;
}
}
}
}
static void capCorrection(input, output);
String text = "";
while (input.hasNextLine()) {
text += input.nextLine() + "\n";
}
final int State_INIT = 0;
final int State_SEEN_I = 1;
int state = State_INIT;