wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Wildcard Characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wildcard Characters" Watch "Wildcard Characters" New topic
Author

Wildcard Characters

Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
Im trying to use and IF else statment, but i need to use wildcard characters;
user input > e,
if (e = "ANY POSTIVE NUMBER") {
Any help would be greatly aperciated.
C. Nimo
Ranch Hand

Joined: Mar 23, 2004
Posts: 82
Hi

This is not a wildcard. This is a range.
you probably want something like
if (e>0)

Nimo.
Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
But it has to be able to handle any postive number
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
I'm guessing e is a String? If its a number, then Nimo has already shown you how to test for any positive number. If however this is a String and you are looking for only positive numeric characters, then look at the JavaDocs on java.util.regex. You'd need a very simple pattern ('\d' or '\p' if its a floating point number)
Herb Schildt
Author
Ranch Hand

Joined: Oct 01, 2003
Posts: 239
If e is a string, you could also convert it into a numeric type, such as int or double, and then use e > o, as shown earlier. For example, to convert a string containing a numeric value into an int, you can use Integer.parseInt(). To convert a numeric string into an double, use Double.parseDouble().


For my latest books on Java, including my Java Programming Cookbook, see HerbSchildt.com
Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
Ive tried and ive tired and i just cant get my head around this question (its in a text book im doing);
A user inputs a certain amount of ram, the computer then outputs how many of 64, 128, 512 and 1024 memory chips are required, it should work in the best value way, e.g 256 = 2 128 chips, not 4 64 chips.
I know that somehow i have to / by each memory amount to get the answer, but ive tried using wild cards to check which is greater than or less then but its not working , any hints, code examples (or the whole code << yeah right lol) would be greatly aperciated, thank you.
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
You don't *have* to use division, though using it would be more efficient.
You could use repeated subtraction by 1024, checking that the result is positive each time, and counting the number of times you have to make a subtraction. When the amount is less than 1024, move to the next largest amount.
From reading your post I'm not sure exactly where your problem is....can you read the user input OK?
If you post your errors / code here people will be able to help you more easily.
Cheers,
--Tim
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

I think it was Polya who said in his book "How to solve it" that one method for approaching a difficult task is to consider a simpler case.
So, try thinking about how you would solve it if you ONLY had 1024MB memory chips.
if i input 7168, how would you figure out how many chips are required? what if i put in 14,336?
once you solve that, add one more size chip, like the 512. then try and solve some made up cases, like 1536 or 7680... then add a third size... eventually you should see a general solution.
OR, try it will even smaller numbers... what if you only had memory chips that were 1, 2, 4, and 8 ? how would you solve it for a value of 7? for 39?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
Thankyou all for the help, the probelm I was having was the math part, put I've fixed it now, (and of course the answer was right in front of me) good ol counters.
Once again thanks everyone.
 
 
subject: Wildcard Characters
 
Similar Threads
java sql query
[regex help]Find EXACT characters in a String.
Question on Creating Generic classes
Wildcard file searches
whats wrong with this picture?