Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Program using String functions

Have Programming Question? Ask it here!
 
 
 


soumyadeep
Program using String functions
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


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

Advertisement
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


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
STRING FUNCTIONS
STRING FUNCTIONS  HERE IS THE QUESTION THAT I HAVE IN MY INFORMATICS... a string and 2 integers from user. It then changes the case of characters at those... String removeCharAt(String s, int pos) { StringBuffer buf = new StringBuffer
Advertisements
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
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
Math Constants and Functions using JavaScript
Math Constants and Functions using JavaScript  What's Math Constants and Functions using JavaScript
associate functions with objects using JavaScript
associate functions with objects using JavaScript  How to associate functions with objects using JavaScript
string program
string program  write a program to print the pattern p r o program r a m
string program
string program  wap to find single occurrence of given string in java without using any predefined method
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
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
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
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
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
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence... prints it is a magic string otherwise it prints not a magic string.  
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
string palindrom using vbscript?
string palindrom using vbscript?  string palindrom using vbscript
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
Retrieve the String using expression
Retrieve the String using expression   ... using expression.For this we are going to make program named NotLookahead.java. The steps involved in program NotLookahead.java are described below:- String
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
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
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
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
Retrieving String by using Regular Expression
Retrieving String by using Regular Expression  ... the way to retrieve the String using Regular expression. For this we are going to make program named LookAhead.java. The steps involved in program
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
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
String Exception Program - JSP-Servlet
String Exception Program  Respected Sir/Madam, I am... the code for your kind reference: <% int val =0; String contentType..., totalBytesRead, formDataLength); totalBytesRead += byteRead; } String file = new
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 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
Interchanging String using RegularExpression
a String and interchange the index of string using Regularexpression. The steps involved in interchanging a String are described below: String parg = "For some... Interchanging String using RegularExpression
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
Replacing String using Regularexpression
Replacing String using Regularexpression       This Example describe the way to replace a String using Regularexpression. The steps involved in replacing a String are described
RARP program using java
RARP program using java   hai, how to implement the RARP concept using java
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
Match string using regular expression without Case sensitivity
Match string using regular expression without Case sensitivity... the way to match the String using regular expression. For this we are going to make program named Matching_Casesensitive.java. The steps involved in program
Replacing all the text of String using expression
Replacing all the text of String using expression... to Replace certain part of the whole String using regular expression. For this we are going to make program named Replaceall.java. The steps involved in program
php Variables and Functions
; how does it help to the program? We create functions to make the program easier... and again. A program contains several functions that can be used several times . ... the program to return some value either in the form of int, float, array, string
how to calculate addition of two distances in feets and inches using objects as functions arguments
how to calculate addition of two distances in feets and inches using objects as functions arguments  how to calculate addition of two distances in feets and inches using objects as functions arguments in java
Reverse String using Stack
Reverse String using Stack You all are aware of Stack, a data structure... the string using these operations. Here is the code: import java.util.*; class StackReverseString { public static String revString(String str) { Stack
How can we get the properties (size, type, width, height) of an image using php image functions?
How can we get the properties (size, type, width, height) of an image using php image functions?  How can we get the properties (size, type, width, height) of an image using php image functions
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
Advertisements
 

 

 

DMCA.com