/*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"); } } }
final File textFile = new File("File to Search.txt");
final BufferedReader in = new BufferedReader(new FileReader(textFile));
// Mapping of String->Integer (word -> frequency)
final TreeMap<String, Integer> frequencyMap = new TreeMap<String, Integer>();
// Iterate through each line of the file
String currentLine;
while ((currentLine = in.readLine()) != null) {
// Remove this line if you want words to be case sensitive
currentLine = currentLine.toLowerCase();
// Iterate through each word of the current line
// Delimit words based on whitespace, punctuation, and quotes
final StringTokenizer parser = new StringTokenizer(currentLine, " \t\n\r\f.,;:!?'"");
while (parser.hasMoreTokens()) {
final String currentWord = parser.nextToken();
Integer frequency = frequencyMap.get(currentWord);
// Add the word if it doesn't already exist, otherwise increment the
// frequency counter.
if (frequency == null) {
frequency = 0;
}
frequencyMap.put(currentWord, frequency + 1);
}
}
// Display our nice little Map
System.out.println(frequencyMap);
#include<stdio.h>
#include<conio.h>
int occurence(char *,int ,char *);
int main()
{
char str[30],str1[20];
int i,j=0,len,n=0;
printf("enter the sentence\n");
gets(str);
printf("enter the word\n");
gets(str1);
for(i=0;str1[i]!='\0';i++);
len=i--;
for(i=0;str[i]!='\0';i++)
{
if((str[i+1]==' ')(str[i+1]=='\0'))
{
n=n+occurence((str+j),len,str1);
j=i+2;
}
}
printf("occurence=%d",n);
getch();
}
int occurence(char *ptr,int m,char *ptr1)
{
int i,count=0;
for(i=0;i<=m;i++)
{
if(*(ptr+i)==*(ptr1+i))
{
count++;
}
}
if((count)==m)
{
return 1;
}
else
{
return 0;
}
}
This functionality is already in Java. String.toLowerCase() and String.toUpperCase() will take care of it for you.
.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......
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 program draw circle and ellipse by using oval methods in java
Write a program that graphically demonstrates the shortest path algorithm
yes ,i can add the website link in java program when we write.
This functionality is already in Java. String.toLowerCase() and String.toUpperCase() will take care of it for you.
.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......
Exactly what do you mean by 'C program in Java'
Check the documentation of the String class, for a method that searches for a substring.
for(int i = 1; i < 100; i+=2) { System.out.println(i); }
write a java program to display "Welcome Java" and list its execution steps.
\n
You can use Java's built-in functions to write a code that will find multilingual languages.
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.
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 program draw circle and ellipse by using oval methods in java