| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
#1 (permalink) |
|
Member
Join Date: Nov 2006
Posts: 32
Thanks: 7 Thanked 0 Times in 0 Posts Thanks: 7
Thanked 0 Times in 0 Posts
Rep Power: 3
|
java program
Hi friends,
Please help me write a program. Write a program to print string with number of occurances. For example if ur input is "welcome to java world. In java world" output is welcome 1 to 1 java 2 world 2 In 1 Pleas help me. Thanks suma |
|
|
|
|
|
#3 (permalink) |
|
Member
Join Date: Sep 2006
Posts: 40
Thanks: 0 Thanked 4 Times in 3 Posts Thanks: 0
Thanked 4 Times in 3 Posts
Rep Power: 5
|
Re: java program
Hello Suma,
Here is the code: import java.lang.*; import java.util.*; public class NoOfOccurence { public static void main(String args[]) { String str = "welcome to java world. In java world"; StringTokenizer st = new StringTokenizer(str,"[ .]"); Vector vec= new Vector(10); HashSet s = new HashSet(); while (st.hasMoreTokens()) { vec.addElement(st.nextToken()); } for (int i = 0; i int count = 0; for (int j = 0; j if(vec.elementAt(i).equals(vec.elementAt(j))) { count = count + 1; } } if (s.add(vec.elementAt(i))) System.out.println(vec.elementAt(i) +"="+ count); } } } Regards, Murali |
|
|
|
| The Following User Says Thank You to muralipn For This Useful Post: |
sumahalesh28 (21-03-07)
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| JAVA WEB SITES | yathish | JAVA Technologies | 2 | 20-11-08 12:11 AM |
| JAVA Q&A part1 | naga | JAVA Technologies | 2 | 27-04-07 12:53 PM |
| JAVA Downloads | yathish | JAVA Technologies | 2 | 22-01-07 01:37 PM |
| java notes | naga | JAVA Technologies | 5 | 22-09-06 10:30 PM |