aspose file tools*
The moose likes Beginning Java and the fly likes Somebody please take a look at this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Somebody please take a look at this

David Barry
Ranch Hand

Joined: Jan 13, 2009
Posts: 83
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

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Jan 13, 2009
Posts: 83
ok. and what is the purpose of the array index again? I forget.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
David Barry
Ranch Hand

Joined: Jan 13, 2009
Posts: 83
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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:



[Jess in Action][AskingGoodQuestions]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Oct 13, 2005
Posts: 40052
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Somebody please take a look at this