Here I have the function tabulation code:

public static void Tabul() { for (double i = 0.2; i <= 2.8; i = i + 0.002) { double y; final double a = 2.3; if (i < 0.3) { y = 1.5 * a * pow(cos(i), 2); } else if (i < 2.3) { y = pow((i - 2), 2) + 6 * a; } else { y = 3 * a * tan(i); } System.out.println("x= " + i + " y=" + y); } } 

Now I need to create a private method with the values ​​of у as the values ​​of the array element. How to do this I can not understand. Tell me. you are welcome!

  • Specify what you mean by " private method with values ​​of у as the values ​​of an array element". - yozh
  • I messed up, I need not only x, but also y. - Julia Danylkina
  • I created a counter, as written in the assignment. It considers how many tabulation steps are: `public static void KTabul () {int k = 0; for (double i = 0.2; i <= 2.8; i = i + 0.002) {k ++; } ` - Julia Danylkina

1 answer 1

Ie you need to keep all values ​​of y?

if so then just redefine y on an array of dimension in the number of points, namely (in your case)

 double[] y = new double[(int)((2.8 - 0.2)/0.002)]; 

and incremental variable. As a result, it remains to replace y with y [z ++] = ...

where z is an int variable declared before the beginning of the loop and initially equal to zero.

  • Forgot +1 at the size of the array. - Qwertiy