Win a copy of The Java Performance Companion this week in the Performance forum!
    Bookmark Topic Watch Topic
  • New Topic

Somebody please take a look at this

 
David Barry
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • 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
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 84
  • Mark post as helpful
  • send pies
  • Report post to moderator
ok. and what is the purpose of the array index again? I forget.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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: 84
  • Mark post as helpful
  • send pies
  • 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.

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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)

 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic