Originally posted by: mdchesne
Yea, i always hated looking up things at the java site cause i never understood how to get it down on paper (or screen, w/e the system.in would be). no for those methods, I tried writing the code but it got wayyy to complicated the way i was trying to write it. Will I need to write a seperate string class so my methods of length and charAt have something to implement?
See my previous statement about thinking too hard
Obtain the string's value by whatever method (command line args, using the
Standard Input Stream, initalize it yourself, whatever) - actually, that link will technically do what you want judging from your explination of the problem - but in this instance, say you declare a String and assign it a value like so in the program:
String myString = "value";
now, you can get the length of the string by using myString.length() - and use a for loop and check each character at the current value of the iteration - just use
myString.charAt(i);
where i is the value in the for loop's current iteration.
This is one easy way to handle it, and if you don't use that standard in, you should be able to do it with very few lines of code not counting your logic to handle the char that is returned.
EDIT: String IS a Class. Don't reinvent the wheel - use Java's implementation so you don't have to write code for something that already exists.. And the Java API is your friend. If you don't use it as a refrence, you are going to have a tough time (massive understatement) in learning or writing efficient code.