3 Replies - 213 Views - Last Post: 01 March 2013 - 01:19 PM Rate Topic: -----

#1 mfaizi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 13

How do i initialize/fill my 2-D array?

Posted 28 February 2013 - 10:22 PM

Hi, this is a homework problem. I do not understand how to fill each column separatly. There are 24 rows and two columns. The left column is supposed to hold multiples of pi/2, and the right column is supposed to hold the tan of the multiple. Here is my coding, it fills both columns with multiples of pi/2. I am a beginner so the simplest answers are appreciated, thank you :)
public class ArrayFunc {

	[public static void main(String[] args) {
		double [][] array = new double[24][2];
	
	    for(int i=0; i<24; i++){
		for(int j =0; j<2; j++){
		
		array[i][j] = (i*(Math.PI/2)) ;
		
		  
			 System.out.print(array[i][j] + "\t");
		}
		System.out.println();
			         
}
}

}

This post has been edited by Atli: 28 February 2013 - 10:24 PM
Reason for edit:: Added [code]...[/code] tags.


Is This A Good Question/Topic? 0
  • +

Replies To: How do i initialize/fill my 2-D array?

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1372
  • View blog
  • Posts: 3,022
  • Joined: 05-April 11

Re: How do i initialize/fill my 2-D array?

Posted 28 February 2013 - 11:42 PM

Easy enough
Just simply remove the nested loop
You know what should be in index 0 and 1 :)
public class ArrayFunc {
	public static void main(String[] args) {
		double[][] array = new double[24][2];
	
	    for(int i=0; i<array.length; i++) {
			array[i][0] = i * (Math.PI/2);
			array[i][1] = //tan of the multiple
			System.out.print(array[i][0] + "\t");
			System.out.print(array[i][1] + "\t");
			System.out.println();         
		}
	}
}



Was This Post Helpful? 1
  • +
  • -

#3 cassiopeia  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 86
  • Joined: 03-April 11

Re: How do i initialize/fill my 2-D array?

Posted 28 February 2013 - 11:45 PM

i post a bit late from CasiOo. since the answer is same, so i remove mine. -_-

This post has been edited by cassiopeia: 28 February 2013 - 11:54 PM

Was This Post Helpful? 0
  • +
  • -

#4 mfaizi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 13

Re: How do i initialize/fill my 2-D array?

Posted 01 March 2013 - 01:19 PM

View PostCasiOo, on 28 February 2013 - 11:42 PM, said:

Easy enough
Just simply remove the nested loop
You know what should be in index 0 and 1 :)/>
public class ArrayFunc {
	public static void main(String[] args) {
		double[][] array = new double[24][2];
	
	    for(int i=0; i<array.length; i++) {
			array[i][0] = i * (Math.PI/2);
			array[i][1] = //tan of the multiple
			System.out.print(array[i][0] + "\t");
			System.out.print(array[i][1] + "\t");
			System.out.println();         
		}
	}
}




View PostCasiOo, on 28 February 2013 - 11:42 PM, said:

Easy enough
Just simply remove the nested loop
You know what should be in index 0 and 1 :)/>
public class ArrayFunc {
	public static void main(String[] args) {
		double[][] array = new double[24][2];
	
	    for(int i=0; i<array.length; i++) {
			array[i][0] = i * (Math.PI/2);
			array[i][1] = //tan of the multiple
			System.out.print(array[i][0] + "\t");
			System.out.print(array[i][1] + "\t");
			System.out.println();         
		}
	}
}




Thanks CasiOo this was very helpful :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1