DO NOT DEAL WITH THIS MEMBER
Say I use a BufferedReader to readLine() from a file which stores the contents of the file as a String.
I want to compare a double generated in the program, say double x = 584.4.
Now the string from the file is "439.8". How can I compare the two double values because when I used the Double.toDouble() is couldn't compare types "Double, and double".
Also, how can I stop a DataOutputStream from clearing the contents of the file every time the object is instantiated?
Use Double.phaiseDouble(string); //Spelt wrong, but you should be able to find it.
What are you using the DataOutputStream for?
DO NOT DEAL WITH THIS MEMBER
(May 3, 2013 01:45 PM).--. Wrote: Use Double.phaiseDouble(string); //Spelt wrong, but you should be able to find it.
What are you using the DataOutputStream for?
It might not be a DOS I think it's a FileWriter or a FileOutputStream.
For FileWriter, if you want to append, do (name of file, true).
It's Double.parseDouble(string)
~ Singularity ~
DO NOT DEAL WITH THIS MEMBER
(May 3, 2013 02:37 PM)vitafortis Wrote: For FileWriter, if you want to append, do (name of file, true).
It's Double.parseDouble(string)
I tried those methods but it throwed a syntax error when I compared type double to Double.
It's only for my Intro to Computer Science class where the skill level is at a point of 3rd grade, and since I finished all the assignments, he told me to learn to write to a File.
(May 3, 2013 02:41 PM)Gpure Wrote: I tried those methods but it throwed a syntax error when I compared type double to Double.
It's only for my Intro to Computer Science class where the skill level is at a point of 3rd grade, and since I finished all the assignments, he told me to learn to write to a File.
Show me your code please. I'll find the error :P
~ Singularity ~
(May 3, 2013 02:41 PM)Gpure Wrote: I tried those methods but it throwed a syntax error when I compared type double to Double.
It's only for my Intro to Computer Science class where the skill level is at a point of 3rd grade, and since I finished all the assignments, he told me to learn to write to a File.
There is a difference between Double and double and I'm sure that's where your problem lies.
Double is a class while double is a primitive so if it is possible switching both to primitives should work.
Difficult to say without looking at the code though.
DO NOT DEAL WITH THIS MEMBER
I don't have the code on my workspace right now, but I'll try and get it monday.
(May 3, 2013 02:41 PM)Gpure Wrote: I tried those methods but it throwed a syntax error when I compared type double to Double.
It's only for my Intro to Computer Science class where the skill level is at a point of 3rd grade, and since I finished all the assignments, he told me to learn to write to a File.
I don't have the java developer kit on this computer, so, I can't really post working code, but, try something along these lines:-
Code Double firstDouble = 45.6
Double secondDouble = Double.parseDouble("45.6");
firstDouble.compareTo(secondDouble) == (Double)0? System.out.println("We match!"); : System.out.println("We don't match");
And post the results, although, I'm sure that's not the most efficient way to test it, it's just the only way I can provide without downloading loads of shit.
OP, it just occurred to me, use a Scanner. It can read doubles just like it would on command line. Just set the input to the file instead of System.in
~ Singularity ~
DO NOT DEAL WITH THIS MEMBER
(May 4, 2013 10:54 AM)vitafortis Wrote: OP, it just occurred to me, use a Scanner. It can read doubles just like it would on command line. Just set the input to the file instead of System.in
And the scanner doesn't return the item from the file as a String?
^ Scratch that...
.nextDouble() would work for a file?
(May 4, 2013 11:25 AM)Gpure Wrote: And the scanner doesn't return the item from the file as a String?
^ Scratch that...
.nextDouble() would work for a file?
Yes. Scanner scanner = new Scanner(file);
It will read in just fine. Not the best way of doing it, but its one way.
~ Singularity ~
|