java - How can I print an array of strings that also has double variables? -


edited remove excess code , show exact errors receiving.

i attempting show array in grid format (like spreadsheet). have declared array of strings, can use readline , split 6 out of 7 columns doubles. keep getting incompatible types errors on of array variables. more specifically: incompatible types: int cannot converted string, incomparable types int , string , incompatible types string cannot converted double new , when researched on here, couldn't find how fix this. here code:

         while(s != null) {           array = s.split(delimiter);           dates = array[0];           dates = integer.parseint(array[0]);           double[] nums = new double[array.length];           (int = 0; < nums.length; i++) {           nums[i] = double.parsedouble(array[i]);           }                  if(dates != 0)  {             open = array[1];             high = array[2];             low = array[3];             close = array[4];             adjclose = array[5];             volume = array[6]; 

java statically typed language. can't take string , pretend it's double. string[] variable always going contain strings. might contain strings doubles, strings.

string[] array = ...; double x = array[0]; 

this type error because we're extracting string array , asking system pretend it's double, won't do.

string[] array = ...; double x = double.parsedouble(array[0]); 

this convert string value double. if data you're getting trusted source (for instance, if it's class , teacher promised data valid), that's fine. if data coming user or other source, double.parsedouble throw exception if data invalid, , need think correct way handle in particular case.

for sake of completeness, here opposite conversion.

string string = x.tostring(); 

any object (and, through trick of java compiler, primitive well) can have tostring called on it, , turn object string.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -