Results 1 to 6 of 6
Thread: Java String Digit Question
- 12-12-2010, 08:03 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
Java String Digit Question
Hey guys im having a bit of trouble here, im not really sure what to do.
So i need to make a method which checks these requirements:
String must have at least eight characters.(Done)
String consists of only letters and digits.
String must contain at least two digits
any idea?
- 12-12-2010, 08:08 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 17
Check each of the characters one by one in a for loop. There are some Character isXXX() methods that are useful.
- 12-12-2010, 08:25 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
im not sure how to do that
- 12-12-2010, 09:03 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 17
Obtaining an array of all the characters in a String: use the String toCharArray() method
Using a for loop to check each element of an array: The for Statement in Oracle's Tutorial
The early sections of the Tutorial also explain a lot of basic Java syntax and usage.
-----------------------------
im not sure how to do that
Break the problem into parts rather than trying to write the program all at once.
* Write some code to obtain an array of characters from a string
then
* Write some code to print the characters one at a time on separate lines
then
* Think about which of the Character methods are useful, and how you would use them to check the string
then
* Write some code to implement the plan you have for checking the string
It's hard to offer specific advice without knowing what you have read and what you have tried. So, post code. If it won't compile and you can't understand the compiler message copy and post that message. If the code compiles and runs but doesn't do what you intend say what it does do.
- 12-12-2010, 09:53 PM #5
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 787
- Rep Power
- 11
Another way would be to work with regular expression, have you already experience with it?
Pattern (Java Platform SE 6)
- 12-12-2010, 10:08 PM #6
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
select a digit in a number
By navid in forum New To JavaReplies: 3Last Post: 12-12-2010, 11:47 AM -
int[] with multi-digit values: toString()
By soccermiles in forum New To JavaReplies: 8Last Post: 04-27-2010, 02:30 PM -
digit spacing
By puk284 in forum New To JavaReplies: 3Last Post: 06-09-2009, 03:49 PM -
Locating a digit within a string
By ScentOfAWookie in forum New To JavaReplies: 8Last Post: 03-27-2009, 06:23 PM -
Java newb Q: 8-digit id
By 1111FM in forum New To JavaReplies: 2Last Post: 09-29-2008, 03:37 PM
Bookmarks