forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_Token_File.java
More file actions
46 lines (41 loc) · 1.39 KB
/
Test_Token_File.java
File metadata and controls
46 lines (41 loc) · 1.39 KB
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
package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Test_Token_File {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
/*if we use pwintwriter to print in file then we have to pass file obj to pwintwriter and mothod to write is println , print
* write or we want to print on console then pass system.out into printwriter and the method is write*/
/*here i use printwriter for console o/p and printstream for file o/p*/
PrintStream ps = new PrintStream("D:/DEEP/java2.txt");
PrintWriter pw = new PrintWriter(System.out);
System.out.println("Enter any random number");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
StringTokenizer st = new StringTokenizer(s);
ps.println("Total Tokens : "+st.countTokens());
pw.write("Total Tokens : "+st.countTokens()+"\n");
int count = 0 ;
while (st.hasMoreElements()) {
String t = (String) st.nextElement();
pw.write("Token is : "+t+"\n");
if(t.contains("5")){
count++ ;
}
}
ps.println("Occurance of 5 is : "+count);
ps.flush();
ps.close();
pw.write("Occurance of 5 is : "+count);
pw.flush();
pw.close();
}
}