question 1 Answer(s) 3 years and 4 months ago
Posted in : Java Beginners
Define a class to accept a sentence & print the no. of words beginning wid the the given character. eg:If the sentence is:"This is The Text" output:no. of words beginning with "T"-3.Here the given character is-T
View Answers
February 9, 2010 at 11:14 AM
Hi Friend,
Try the following code:
import java.util.*; class Words{
public static void main(String[] args){ int count=0; Scanner input=new Scanner(System.in); System.out.print("Enter string:"); String st=input.nextLine(); System.out.print("Enter character to count:"); String s1=input.next(); StringTokenizer stk=new StringTokenizer(st); while(stk.hasMoreTokens()){ String str=stk.nextToken(); char ch=str.charAt(0); String s2 = Character.toString(ch); if(s1.equals(s2)){ count++; } } System.out.println(s1+"-"+count); } }
Thanks
Related Pages:
question question sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question question sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question Question When there is an exception in my program how java runtime system handles
question
question dear sir/madam
my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question Dear sir
i had some typing mistake at previous question
so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
question
question Gud morning sir,
I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details.
There is a entity name
Question? Question? My question is how to:
Add a menu bar to the program with a File menu.
In the File menu, add a submenu (JMenuItem) called About.
When the user clicks on the About menu item, display a JOptionPane message dialog