• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

float

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Marshal
Posts: 79670
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79670
381
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome, and thank you for changing your name.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Die Fledermaus does not fear such a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic