This content has been marked as final. Show 16 replies
You could use java.util.Scanner, or regular expressions directly -- the classes of java.util.regex.
I know I can use the Scanner, I can make a method that returns true if it reads an integer but how can I count the actual numbers then?
try something like this:
String text = "12ab34cd56ef"
String numberList = text.split("[^0-9]+");
The number of (group of) integers would then be numberList.length.
But for my assignment I have to make a method that checks if the character is an integer and then returns true or false. Have any ideas?
I think we've already done most of your homework. Can you do the rest?
character = a single character
string = one or more characters
so do you need a method to tell if one character is an integer
or on an entire String?
Just one more hint: chars are primitives so you can use logical operators (== != < etc) to compare them.
but what's the code for reading a String character per character?
Ok,Check the API: http://java.sun.com/javase/6/docs/api/java/lang/String.html
but what's the code for reading a String character
I have seen plenty of people complain how useless their teacher is and the most often response is that the OP is useless and just because they don't understand they blame the teacher.
However, it amazes me the number of students that don't seem to know about the API. So is it a matter that the teachers haven't explained it to them or just another example of how useless and lazy the student is that they can't be bothered to look up the API for themselves?
When I taught programming and a student asked:
* What package is class XYZ in?
* Does XYZ have a method to do blat?
* What does method f of XYZ do?
Instead of giving them the answer, I would show them
how to look it up. Finally someone would pull himself
up short: "Is there a method to --- wait, are you just going
to tell me to look it up in the API?" Indeed.
It reminds me when I was a kid and asked my mother what a word meant. She'd tell me to look it up in the dictionary.
It reminds me when I was a kid and asked my motheromg, you just brought up my greatest pet peeve.
what a word meant. She'd tell me to look it up in the
i was raised to be curious and to find my answers in dictionaries,
encyclopedias and book indices.
id take a wild guess that 50% of americans dont know what an
index is or when to use it. it is absolutely infuriating.
sigh... not that it matters. in 10 years everything will be online.
id take a wild guess that 50% of americans dont know what anindex is or when to use it. it is absolutely infuriating.
I recently watched "Treasure Hunters" on tv. The teams had to locate a book in the Library of Congress and were wandering aimlessly around not knowing
that they could look the books up in the card index. Astounding!