Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can have an array as an argument for your constructor</p> <pre><code>public class MultiDemPoint{ public MultiDemPoint(double[] coords){ } } </code></pre> <p>You will need to pass an array of doubles: </p> <p><code>new MultiDemPoint(new double[]{4, 5.0, 3, 2, 6, 4.6});</code></p> <hr> <p>You can also expect undefined number of coordinates as separated values</p> <pre><code>public class MultiDemPoint{ public MultiDemPoint(double... coords){ } } </code></pre> <p>You can pass parametrs like <code>new MultiDemPoint(4, 5.0, 3, 2, 6, 4.6);</code> in this case.</p> <hr> <p>Practice:</p> <ul> <li>Create a new empty project in your IDE</li> <li><p>Create <code>MultDemPoint.java</code> file with following code:</p> <pre><code>public class MultiDemPoint{ private double[] coords; //double... coords will automatically convert all supplied coordinates to the array, // we can store it in double[] coords. public MultiDemPoint(double... coords){ this.coords = coords; } public void printCoords(){ for(int i=0; i&lt;coords.length; i++){ System.out.println("Coordinate #"+i+": "+coords[i]); } System.out.println(""); } } </code></pre></li> <li><p>Use this code for your <code>Main.java</code></p> <pre><code>public class Main { public static void main(String[] args){ MultiDemPoint point1 = new MultiDemPoint(1,2,3,4); MultiDemPoint point2 = new MultiDemPoint(3); MultiDemPoint point3 = new MultiDemPoint(5.44444444,232323.12323,321321); System.out.println("Point1 coordinates:"); point1.printCoords(); System.out.println("Point2 coordinates:"); point2.printCoords(); System.out.println("Point3 coordinates:"); point3.printCoords(); } } </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload