-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEveryOther
59 lines (47 loc) · 1.59 KB
/
EveryOther
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class EveryOther {
public static void main(String args[]) throws FileNotFoundException {
File inputFile = new File("inputfile.txt");
File outputFile = new File("outputfile.txt");
Scanner keyboard = new Scanner(System.in);
Scanner fileScan = new Scanner(inputFile);
PrintWriter input = new PrintWriter(inputFile);
PrintWriter output = new PrintWriter(outputFile);
String keyInput = "";
String hold1 = "";
String hold2 = "";
String hold3 = "";
String custom = "";
System.out.println("Type first a custom symbol and then whatever and then to stop type a plus sign");
keyboard.useDelimiter("");
hold1 = keyboard.next();
custom = hold1;
while(!hold1.equals("+")){
keyInput += hold1;
hold1 = keyboard.next();
}
keyboard.close();
input.write(keyInput);
input.close();
while(fileScan.hasNextLine()){
hold2 = fileScan.nextLine();
int lngth = hold2.length();
int k = 0;
while(k < lngth) {
if(hold2.substring(k, k + 1).equals(" ")) {
output.write(custom);
k++;
} else {
output.write(hold2.substring(k, k + 1));
k++;
}
}
output.write(custom);
}
fileScan.close();
output.close();
}
}