The Artima Developer Community
Sponsored Link

Java Answers Forum
HELP me in this code

1 reply on 1 page. Most recent reply: Aug 9, 2004 12:08 AM by Vaibhav

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
mahmoud

Posts: 1
Nickname: poprage
Registered: Aug, 2004

HELP me in this code Posted: Aug 8, 2004 9:15 AM
Reply to this message Reply
Advertisement
i have an application that i want to make , the user is supposed to enter 1 sentence or more as he wants , & i am supposed to count the repetition of each word

i.e. if he wrote "I am the user I am the user" the program should give an output like

I 2
am 2
the 2
user 2

so in order to solve it i have to use StringTokenizer but the problem is how can i save each word & compare it with the 1 behind it ?????

using an array ???? & how can i use it & how can i print them ??????

2 long but i really need it

thx in advance.


Vaibhav

Posts: 4
Nickname: vaibhz
Registered: Aug, 2004

Re: HELP me in this code Posted: Aug 9, 2004 12:08 AM
Reply to this message Reply
Hi,

This is the dirtiest logic u can find but u can review and modify as per ur requirement ;)

Hope it helps u....

import java.util.*;

class Help
{
public static void main(String[] args)
{
String testString= "I am the user I am the user", token = null,temps;
int i =0;
StringTokenizer st = new StringTokenizer(testString," ");
StringTokenizer tempst;

while (st.hasMoreElements())
{
token = st.nextToken();
tempst = new StringTokenizer(testString," ");
while (tempst.hasMoreTokens())
{
temps = tempst.nextToken();
if (temps.equals(token))
{
i++;
}
}
System.out.println(token+" "+i);
i = 0;
}
}
}

Flat View: This topic has 1 reply on 1 page
Topic: Java Applet and IIS Previous Topic   Next Topic Topic: using jar

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use