Program using String functions

Ads
 

Program using String functions

Write a program to accept a sentence and find out how many times the word "the" occurs?
View Answers

August 9, 2010 at 11:05 AM

Hi Friend,

Try the following code:

import java.util.*;

class CountSameWords {

public static void main(String[] args) {
int count = 0;
Scanner input = new Scanner(System.in);
System.out.print("Enter string:");
String st = input.nextLine();
String s1 = "the";
StringTokenizer stk = new StringTokenizer(st);
while (stk.hasMoreTokens()) {
String str = stk.nextToken();
if (s1.equalsIgnoreCase(str)) {
count++;
}
}
System.out.println(s1 + "-" + count+" times");
}
}

Thanks

Ads









Related Tutorials/Questions & Answers:
Program using String functions - Java Beginners
Program using String functions  Write a program to accept a sentence... { public static void main(String[] args) { int count = 0...); System.out.print("Enter string:"); String st = input.nextLine
Java reverse string without using inbuilt functions
Java reverse string without using inbuilt functions In this tutorial, you will learn how to reverse string without using any inbuilt functions. Here, we have created a method to reverse the string and returns a new string with reverse
Advertisements
without using built-in functions
without using built-in functions  Hai sir... Please help me to solve this... Findout occurances of each string in every another string (built - in functions are not at all allowed) all, and, sand, falling wall and sand
string program
string program  wap to find single occurrence of given string in java without using any predefined method
string program
string program  write a program to print the pattern p r o program r a m
string program
string program  reads sentence and find the average length of word... AverageLengthOfWords { public static void main(String[] args...); System.out.print("Enter sentence: "); String st=input.nextLine(); String str
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
String reverse program
String reverse program  write a java program for reverse string? if the string is "Hi welcome to hyderabad" the reverse string is "hyderabad... for help. You can split the String into String array using split method of String
string palindrom using vbscript?
string palindrom using vbscript?  string palindrom using vbscript
Program to swap the string
and then swaps both the string without using third variable. import java.util.*; class...Program to swap the string  Hi, can any one tell me the code to swap the 2 strings without using temporary varibales??? Thanks a lot in advance
greatest of 3 numbers using classes and functions.
greatest of 3 numbers using classes and functions.  WAP to calculate greatest of 3 numbers using classes and functions with parameters through input... FindLargest{ public static void main(String[] args){ int max = Integer.MIN
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
Reverse String Program in Java
in String Java reverse string without using inbuilt functions...Reverse String Program in Java We are going to describe about reverse string program in java. In this example reverses a string entered by the user. We
Search string using substring
Search string using substring  I want to print a string by searching a substring of that string. - i want to print email-ids from word files (resumes) in a directory. Search can be made using @ in the word file. So far i can
Input - Output String Functions
Input - Output String Functions       This tutorial is showing some functions that you need to use for your taking... a string data and input them directly into your database. Some special characters
Find String Values of Cell Using POI
Find String Values of Cell Using POI       In this program we are going to find the String Values of Cell of  an excel sheet using POI3.0 API Event. The class 
A Program To Reverse Words In String in Java
A Program To Reverse Words In String in Java  A Program To Reverse Words In String in Java for example: Input:- Computer Software Output :- Software Computer without using split() , StringTokenizer function or any extra
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
Passing a parameter using URL string
Passing a parameter using URL string  How to pass a parameter using the URL string in a JSF application
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
program using StringTokenizer
program using StringTokenizer  I want to know about StringTokenizer,so can you please explain it with an example
String Reverse Using StringUtils
String Reverse Using StringUtils       In this example we are going to reverse a given string using StringUtils api. In this example we are reversing a string and the reversed
String Functions In Java
String Functions In Java In this section we will see various methods of String...(String anotherString) : This method compares two strings using Unicode value... compareToIgnoreCase(String str) : This method compares two strings using Unicode
Creating objects for classes and calling functions of a dll file using JNI
Creating objects for classes and calling functions of a dll file using JNI .... In this file, some c++ classes and functions are available. How can we create objects for these classes and how can we call these functions by using JNI. Am
java program using control statements...
java program using control statements...  public class ControlStatements { public static void main(String args[]){ int x=10; if(x==0...("It is negative number"); }}} in this program what and where it is error and why

Ads