Results 1 to 5 of 5
Thread: Convert from string to double
- 12-12-2010, 05:07 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Convert from string to double
Okay so im tring to convert a string to a double, but i keep geting a error saying: incompadible types found double but expected java.lang.string
i already tried switching things around but i cant get it to work.
this is the peice of code that im useing:
This is the piece that i keep geting the error:Java Code:import java.util.Scanner; import java.io.*; public class Ice_Cream_Menu { public static void main(String args[]) throws IOException { System.out.print("\f"); String X = ""; String filename; filename = "Prices.txt"; File file = new File(filename); Scanner inputFile = new Scanner(file); Scanner keyboard = new Scanner(System.in); final int total = 30; double prices[] = new double[total]; String product[] = new String[total]; for(int r=0; r<total; r++) { product[r] = inputFile.nextLine(); X = inputFile.nextLine(); product[r] = Double.parseDouble(X); // This is were im haveing the error. } inputFile.close();
Java Code:for(int r=0; r<total; r++) { product[r] = inputFile.nextLine(); X = inputFile.nextLine(); product[r] = Double.parseDouble(X); // This is were im haveing the error. }
-
Please post the actual error message. Learning to understand these is paramount.
- 12-12-2010, 05:20 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
- 12-12-2010, 05:20 PM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
You declared product as a String[], and you are trying to assign a double to product[r]. My guess is you meant to assign it to prices[r].
-Gary-
- 12-12-2010, 05:27 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
How to convert a double into a int?
By tyang in forum New To JavaReplies: 4Last Post: 02-10-2010, 10:02 AM -
convert String to Double
By azurovyhrosik in forum CLDC and MIDPReplies: 5Last Post: 10-22-2008, 02:46 AM -
convert string to a double?
By javaMike in forum Advanced JavaReplies: 2Last Post: 11-27-2007, 03:10 AM -
type mismatch: cannot convert from double to float
By bugger in forum New To JavaReplies: 2Last Post: 11-16-2007, 01:24 PM -
Help with convert a double type number
By trill in forum New To JavaReplies: 1Last Post: 08-06-2007, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks