aspose file tools*
The moose likes Java in General and the fly likes float Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "float" Watch "float" New topic
Author

float

Lily Zulkipli
Greenhorn

Joined: Sep 22, 2011
Posts: 8
Dear Java experts.Help! I'm 1 month beginner.



This is my TextFile

a 54 AB123 Orange Pte Ltd

I have problem with AB123

[Edit - added code tags - MB]
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Greetings and welcome to the Ranch.

While we analyze your problem, please read http://www.javaranch.com/name.jsp and correct your username.

If that is your name... Kewl one!
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

But your main issue is that you are trying to convert the String AB123 to a float. And it is not a float.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4392
    
    8

Hi Lily. Welcome to The Ranch!

We can help you more effectively if you let us know exactly what error you're getting, or what it's doing that you don't expect.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

I made some changes in your code.




I think what you have missed is how the Scanner works. The method nextFloat() won't lookup the next suitable float, it will look at the next token and see if it fits into a float. Same with hasNextFloat().
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Actually hasNextFloat is useful if there are problems.But why are you using floats in the first place? You don't usually use floats for retailer codes. If the retailer is ABC123, that's a String, and you can pick it up with the next() method in your Scanner.
You won't get much output from printf if you don't have any % tags.
Lily Zulkipli
Greenhorn

Joined: Sep 22, 2011
Posts: 8
AB123 is a combination of letters and digits. I thought if it's combined, it's float since we've never used this before.

Thank You ALL so much! this forum really does help me. Congratulations for creating this forum!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
You're welcome, and thank you for changing your name.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

Lily Zulkipli,
Your post was moved to a new topic.
Please don't add a new, unrelated question to an existing post.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
jQuery in Action, 2nd edition
 
subject: float