Changin type int to type double.. Java

Discussion in 'Programmer's Corner' started by Ben_C, Mar 15, 2012.

  1. Ben_C

    Thread Starter Active Member

    Oct 19, 2010
    65
    4
    Ive got some code that is int but needs to be double as I need it to have values to 1 decimal place.. I've simply changed it to double where it says int but when i compile it it gives an error saying:
    found: double
    expected: int

    :S

    Well confused.

    Code ( (Unknown Language)):
    1. int firstarray[][] = {{a,b,c},{d,e,f},{g,h,i}};
    2.  System.out.println("The readings are");
    3.  display(firstarray);
    4.  }
    5.  public static void display (int x[][]){
    6.    for (int row=0;row<x.length;row++){
    7.       for (int column=0;column<x[row].length;column++){
    8.  
    9.   System.out.print (x[row][column]+"\t");
    10.  }
    11.   System.out.println();
    Ive changed it to:

    Code ( (Unknown Language)):
    1. double firstarray[][] = {{a,b,c},{d,e,f},{g,h,i}};
    2.  System.out.println("The readings are");
    3.  display(firstarray);
    4.  }
    5.  public static void display (double x[][]){
    6.    for (double row=0;row<x.length;row++){
    7.       for (double column=0;column<x[row].length;column++){
    8.  
    9.  System.out.print (x[row][column]+"\t");
    10.  }
    11.  System.out.println();
    But this give me the error... All the other code (double) compiles up until this point, i just cant figure it out.
    Help?
     
    Last edited: Mar 15, 2012
  2. Ben_C

    Thread Starter Active Member

    Oct 19, 2010
    65
    4
    Im a genius ive done it haha, heres how..

    Code ( (Unknown Language)):
    1. double firstarray[][] = {{a,b,c},{d,e,f},{g,h,i}};
    2.  System.out.println("The readings are");
    3.  display(firstarray);
    4.  }
    5.  public static void display (double firstarray[][]){
    6.    for (int row=0;row<firstarray.length;row++){
    7.       for (int column=0;column<firstarray[row].length;column++){
    8.  
    9.  System.out.print (firstarray[row][column]+"\t");
    10.  }
    11.  System.out.println();
     
Loading...