String array logic question with java I/O -
i need read line file: 5 chair 12.49 edit: want able have more lines of data.
i need separate each word/number different data types. first 1 int, second string, third double. need have them formatted this: item: chair price: $12.49 quantity: 5
now know how format, problem having parsing string elements respected data types (int, string, double).
i've tried:
string [] lines = lineinput.split(" "); for(string displaylines : lines) { bufferedwriter.write(displaylines); bufferedwriter.newline(); system.out.println(displaylines); }
but separates each string new line , couldn't life of me figure out how have each line check if it's int, string or double.
then messing substring, couldn't work. thought of using mod % function , if:
if(lines.length % 2 == 0) {it's string};
but work first line.
please believe me when i've tried on own , not making half-trying effort. giving up. stackoverflow, you're hope :(
if have lines format [int] [string] [double], can do:
string [] line = lineinput.split(" "); int x = integer.parseint(line[0]); string s = line[1]; double d = double.parsedouble(line[2]);
you can modify necessary handle lines different formats.
Comments
Post a Comment