So new to the whole Java shindig thats going on over here, I am 1 month down in my 4 year software engineering degree, And I am already stumped on how to pull doubles from a string using a Scanner. The code is a mess, and I'm sure it doesn't make much scene but working on one problem at a time,
Any point in the right direction would be amazing!
Cj Turner wrote:Thanks for the speedy reply, I since posting this have worked out my initial problem, and have moved onto others... This is my code as it stands,
Now the issue with this is, where I have
The second if statement returns the current value, while the first always returns 0,
I'm sure the tempNum is assigned a value before it reaches the if, so it should have something greater than 0 to store there?
I think the only issue is with if block.
Try below code instead of your if blocks:
Hope you will get proper answer.
Joined: Oct 13, 2005
Where are you initialising tempNum? Why are you using two Scanners? You only need one. Don't use nextLine() if you want a number, use nextXXX(). Don't pass the result from one Scanner to another, which is unnecessary.
You can enter several doubles and read them in a loop, like this
Enter your numbers: 1.23 2.34 3.45
Enter more numbers, or "close" to finish: 4.56 5.67 close
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com