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

Somebody please take a look at this

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi everybody. I have taken a different approach to the writing of this code. However, when I try to run it, it says possible loss of precision and highlights this line: " theTemps[index] = inFile.next();". I am wondering why it says possible loss of precision. Thanks
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
that's an interesting error message alright.

well think of this: what is an array index only allowed to be? (hint: it's not a double).

once you fix that, you'll have your next problem (incompatible types)... but fix the index problem first.

(and once you fix that, you'll have your third problem, but at least it will compile).
 
David Barry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
ok. and what is the purpose of the array index again? I forget.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

David Barry wrote:ok. and what is the purpose of the array index again? I forget.


think of an array as an egg carton - it simply holds things. The index is used to identify the SPECIFIC egg in the carton. So, would you say "Take egg #3.2 out of the egg carton"?

probably not. you'd probably only use whole numbers - i.e. numbers without a decimal part.
 
David Barry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
What do you think my third problem is? I now have this code that compiles, but does not print out my doubles from the text file.

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You can't display the contents of an array this way:

System.out.println(theTemps);

You have to use a loop and print each element. There are a million ways to do this, but here's one:

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

David Barry wrote:What do you think my third problem is? I now have this code that compiles, but does not print out my doubles from the text file.



Your 3rd problem is that your index is not moving. To take someone else's example, you are smashing each new egg you pick up from inFile, into the same spot, every time through the loop. What happens to the metaphorical eggs, is what happens to your previous numbers.

you need to be incrementing the value of index, each time through the loop.

Finally, you might encounter a fourth problem (ponder what happens when there are more than 14 values in the file you are reading)

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You would have done better to post this as a continuation of your earlier thread. And I have already told you "Somebody please take a look at this" is not a suitable thread title.

I am not getting at you. We want to help, but it is more difficult if you don't keep threads together, or use such vague titles.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic