• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wildcard Characters

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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

Nimo.
 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But it has to be able to handle any postive number
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Author
Posts: 253
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic