Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

float

 
Lily Zulkipli
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48917
58
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome, and thank you for changing your name.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lily Zulkipli,
Your post was moved to a new topic.
Please don't add a new, unrelated question to an existing post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic