Results 1 to 5 of 5
- 11-28-2012, 08:57 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 40
- Rep Power
- 0
-
Re: can you parse to get data for an array?
I know of no automatic plug in and parse to array. You need to write code for that. You may use a Scanner object for this, or any other object that will accept input.
- 11-28-2012, 11:33 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 40
- Rep Power
- 0
Re: can you parse to get data for an array?
Thanks.
I thought that was the case.
I'm trying to use scanner to get input from a jTextField without much luck. Parsing was easy but it needs to go into an array, so no parsing.
I have the line -
The problem is, I need to get the input into a double for the array and math to follow.Java Code:Scanner minutesIn = new Scanner(minutesField.getText());
I tired to add this line afterwards to turn the input into a double but it obviously doesn't work
I guess I need to somehow combine these 2 lines so it works, just not sure how.Java Code:double minutesIn = minutesIn.nextDouble();
EDIT:
I've changed things a bit. I'm now using this line -
Now, I need to use the scanner on this to get it into my array.Java Code:double minutesIn = Double.parseDouble(minutesField.getText());
Problem is I have no idea how to do this.Last edited by neveser; 11-29-2012 at 12:41 AM.
- 11-29-2012, 01:37 PM #4
Re: can you parse to get data for an array?
I'm really confused by your question and subsequent post. Are you trying to tokenize an input, convert a String to a double, or what?
Your final example using Double.parseDouble is the correct way to convert the String representation of a double into an actual double data type. What data type does your array hold? Most likely you just need to cast.
- 11-30-2012, 01:47 AM #5
Member
- Join Date
- Nov 2012
- Posts
- 40
- Rep Power
- 0
Re: can you parse to get data for an array?
The data needs to be a double. I did find out that the second example was the way to go. Now I'm just having trouble getting the 2 user inputs into a 2D array. The first input works fine but the second produces an error. Since it's a new problem, I made a seperate thread, Second number not getting into 2D array
Similar Threads
-
Parse Data from Java Applet
By ssh1091 in forum Java AppletsReplies: 6Last Post: 02-27-2011, 03:28 AM -
How can I parse the data ?
By krr in forum CLDC and MIDPReplies: 5Last Post: 08-21-2010, 03:01 PM -
Using Tokenizer to parse file data--CODE
By Cylab in forum Java SoftwareReplies: 0Last Post: 07-26-2010, 11:48 AM -
add data into an array
By mispeed in forum New To JavaReplies: 9Last Post: 11-08-2007, 03:53 AM -
Add data to an array
By adlb1300 in forum New To JavaReplies: 8Last Post: 11-05-2007, 02:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks