-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExperiment12.java
50 lines (42 loc) · 1.46 KB
/
Experiment12.java
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
import java.io.*;
public class Experiment12 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the no of numbers to be inputed: ");
int n = Integer.parseInt(br.readLine());
FileOutputStream fo = new FileOutputStream("Numbers.txt");
System.out.print("Enter the numbers: ");
for(int i=0; i<n; i++) {
fo.write(Integer.parseInt(br.readLine()));
}
fo.close();
FileInputStream fi = new FileInputStream("Numbers.txt");
FileOutputStream feo = new FileOutputStream("Even.txt");
FileOutputStream foo = new FileOutputStream("Odd.txt");
for(int i=0; i<n; i++) {
int temp = fi.read();
if(temp % 2 == 0) {
feo.write(temp);
}
else {
foo.write(temp);
}
}
fi.close();
feo.close();
foo.close();
FileInputStream fei = new FileInputStream("Even.txt");
FileInputStream foi = new FileInputStream("Odd.txt");
System.out.print("Even Numbers\n");
int temp;
while ((temp=fei.read()) != -1){
System.out.print(temp+"\n");
}
System.out.print("Odd Numbers\n");
while ((temp=foi.read()) != -1) {
System.out.print(temp+"\n");
}
fei.close();
foi.close();
}
}