The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

boogalooga

Posted by Chin Loong on November 10, 2001 at 10:46 PM

Generators? Wrapper classes? Wow, sounds too hardcore for me.. ;)

Peter, I think Matt is already being very specific by giving u the link to the book itself. Do you want him to even look for the exact page where the exact problem is for you? Come on, it's your assignment, do some work please. An advice for that little problem of "make me forget the little I have learnt", write watever u have learnt down in a journal or a paper ;). Then u won't forget them.

From what i can see, these methods are for :

charAt() - to get the specific character from the string, and possibly the array, and compare both to see whether it's equal or not.


String str="boogalooga";
for(int i=0;i {
char ch=str.charAt(i); // gets the certain character
// from here you get your character from the array
// and compare it, if it's equal, add the counter in
// your counter array or if you don't want to fetch every
// single character, look at the indexOf() explanation below.
}

indexOf() - well this is just to save you from looking at redundant characters, rather than checking every characters from the *beginning* of the array of either your string or character list (you can store your character list as a string, or well, an array), you just use indexOf() to get the first occurence of the character.

> I would like to complete this problem in the simplest way possible...
> Generators seem like stuff for hardcore programmers...is it possible to use Wrapper classes and the attributes listed above in solving the problem....????

> P/S(Matt Gerans could u be more specific...as the book seems more likely to confuse me more and make me forget the little I have learnt....)


> > I suppose you could squeek the info into an array of length 27, assuming 'a' is at index 0 and so on (with index 26 being the catch all), but my guess is that your instructor may have intended this to be an exercise in using maps. Maps are often used to solve these categorizing problems. You can easily find such examples in the tutorials. You could also find an example of this exact problem in Bruce Eckel's Thinking in Java book, which you can get online for free at his web site.

> > - mfg

> >
> > > I'm new to programming and I'm writting a program..that is supposed to capture the value...command line... a user inputs and checks that word for all the characters and displays them as an array...

> > > i.e. java CommandLine "all java applications contains a static main method."
> >


> > > produces
> > > letter Freq
> > > ===== ===
> > > a 9
> > > c 3
> > > d 1
> > > e 1
> > > h 1
> > > i 5
> > > j 1
> > > l 3
> > > m 2
> > > n 4
> > > o 3
> > > p 2
> > > s 3
> > > t 5
> > > v 1
> > > others 10
> >

> > > The code I have so far...
> > > class CommandLine{

> > > // MY PROBLEM HOW TO USE THE STRING ATTRIBUTES AND ARRAY ATTRIBUTES
> > > // so how would i implement it in this method?
> > > //This being a class that gets the value the user entered as a
> > > command line arguments........
> > > public int [] freq(String s)
> > > {
> > >
> > > for(int i = 0; i> > >
> > > char chr = s.charAt(i);//returns char value
> > > int indexOf = s.indexOf(i); //returns position....

> > > What should I do before I can call the method to main?????
> > > Anyone have ideas...

> > >
> >





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us