answersLogoWhite

0

/*this block of code fineds any given string in tree different file

displays the string and prints the number of occurences in these file....thats all:)*/

package useToken;

import java.io.*;

class readFile extends StreamTokenizer {

readFile(InputStream in ){

super(in);

}

public static void main (String argv[]){

try {

int ret;

String string;

BufferedReader in =

new BufferedReader (newInputStreamReader(System.in));

System.out.print("Enter some text: ");

string = in.readLine();

String[] file = {"file1.txt","file2.txt","file3.txt"};

for(int i=0;i<3;i++){

FileInputStream fin = new FileInputStream(file[i]);

readFile rt = new readFile(fin);

int counter =0;

while((ret = rt.nextToken())!= 0 && rt.sval != null){

if(rt.sval.equals(string)){

System.out.println("Found Text :" + rt.sval );

counter++;

}

}

System.out.println("The String Found :" + counter + " " + "times");

System.out.println(file[i] + " " + "Complete");

}

} catch (Exception e ){

System.err.println("Exception :" + e);

}

}

}

Write a program to find the frequency of words in a sentence in java programing?

//program to find occurence of a word in a sentence

import java.io.*;

public class cnt2

{

public static void main(String args[])throws IOException

{

int times=0,count=0,x=0,no=0;

InputStreamReader ir=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(ir);

String s,w;

System.out.println("Enter the sentence:");

s=br.readLine();

System.out.println("Enter the word:");

w=br.readLine();

try{

for(int i=0;i

{

if(w.charAt(0)==s.charAt(i))

{

for(int j=0;j

{

if(s.charAt(i)==w.charAt(j))

{ count=count+1;}

if(count==w.length())

{no=no+1;count=0;};

}

}

}

catch(Exception e){}

if(no==0)

{

System.out.println("word is not present");

}

else

{

System.out.println("word is present "+no+" times");

}

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Can we add website link when we write java program?

yes ,i can add the website link in java program when we write.


Write a program to change the case of the given string?

This functionality is already in Java. String.toLowerCase() and String.toUpperCase() will take care of it for you.


Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


Write a java program to find sum of even and odd numbers in given array?

for(int i = 1; i &lt; 100; i+=2) { System.out.println(i); }


Write a Java Program to find occurences of given word in a text?

Check the documentation of the String class, for a method that searches for a substring.


What is javadoc?

write a java program to display "Welcome Java" and list its execution steps.


How write new line program in java?

\n


How do you write a java program for finding multiligual languages?

You can use Java's built-in functions to write a code that will find multilingual languages.


How java is 100 percent Internet based?

It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


Write a java code to draw a circle inside in an ellipse?

write a program draw circle and ellipse by using oval methods in java