Commit d387b823 authored by MARIO LLESTA MUÑOZ's avatar MARIO LLESTA MUÑOZ
Browse files

WordCounter.java

parent abff46ba
package packageTwitter;
import java.io.*;
public class WordCounter {
public static void main(String[] args) throws IOException {
File fichero = new File ("C:/Users/mlles/eclipse-workspace/cryptanalysis/CryptoTotal.txt");
String[] words=null;
String[] words2=null;
FileReader fr = new FileReader(fichero); //Creation of File Reader object
BufferedReader br = new BufferedReader(fr); //Creation of BufferedReader object
String s;
String inputBTC="btc";
String inputBTC2="BTC";
String inputBTC3="#btc";
String inputBTC4="#BTC";
String inputBTC5="Bitcoin";
String inputBTC6="#Bitcoin";
String inputBTC7="$btc";
String inputETH="eth";
String inputETH2="ETH";
String inputETH3="#eth";
String inputETH4="#ETH";
String inputETH5="Ethereum";
String inputETH6="#Ethereum";
String inputETH7="$ETH";
String inputSHIB="shib";
String inputSHIB2="shiba";
String inputSHIB3="#shib";
String inputSHIB4="#SHIB";
String inputSHIB5="#shiba";
String inputSHIB6="#Shibainu";
String inputSHIB7="Shiba";
String inputNFT = "nft";
String inputNFT2 = "#nft";
String inputNFT3 = "NFT";
String inputNFT4 = "#NFT";
String inputNFT5 = "NFTs";
String inputNFT6 = "#NFTs";
// Input word to be searched
int count = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
while((s=br.readLine())!=null){
words=s.split(" "); //Split the word using space
// ||word.equals(input2)|| word.equals(input3)
for (String word : words) {
if ((word.equals(inputBTC)) || (word.equals(inputBTC2)) || (word.equals(inputBTC3))
|| (word.equals(inputBTC4)) || (word.equals(inputBTC5)) || (word.equals(inputBTC6))
|| (word.equals(inputBTC7)))
{
count++; //If Present increase the count by one
}
}
for (String word : words) {
if ((word.equals(inputETH)) || (word.equals(inputETH2)) || (word.equals(inputETH3))
|| (word.equals(inputETH4)) || (word.equals(inputETH5)) || (word.equals(inputETH6))
|| (word.equals(inputETH7)))
{
count2++; //If Present increase the count by one
}
}
for (String word : words) {
if ((word.equals(inputNFT)) || (word.equals(inputNFT2))
|| (word.equals(inputNFT3)) || (word.equals(inputNFT4))
|| (word.equals(inputNFT5)) || (word.equals(inputNFT6))){
count3++; //If Present increase the count by one
}
}
for (String word : words) {
if ((word.equals(inputSHIB)) || (word.equals(inputSHIB2)) || (word.equals(inputSHIB3))
|| (word.equals(inputSHIB4)) || (word.equals(inputSHIB5)) || (word.equals(inputSHIB6))
|| (word.equals(inputSHIB7)))
{
count4++; //If Present increase the count by one
}
}
}
if(count!=0) //Check for count not equal to zero
{
System.out.println(inputBTC + " is present for "+count+ " Times in the file");
}
else
{
System.out.println("The given word is not present in the file");
}
fr.close();
if(count2!=0) //Check for count not equal to zero
{
System.out.println(inputETH + " is present for "+count2+ " Times in the file");
}
else
{
System.out.println("The given word is not present in the file");
}
fr.close();
if(count3!=0) //Check for count not equal to zero
{
System.out.println(inputNFT + " is present for "+count3+ " Times in the file");
}
else
{
System.out.println("The given word is not present in the file");
}
if(count4!=0) //Check for count not equal to zero
{
System.out.println(inputSHIB + " is present for "+count4+ " Times in the file");
}
else
{
System.out.println("The given word is not present in the file");
}
fr.close();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment