Course Solutions Uncategorized (Solved) : Java Please Explain Line Code Detail Code Arrayssort Points New Comparey Import Javautilar Q27336850 . . . .

(Solved) : Java Please Explain Line Code Detail Code Arrayssort Points New Comparey Import Javautilar Q27336850 . . . .

 

[JAVA]

Please explain what this line of code does in detail in the codebelow

Arrays.sort(points, new CompareY());

——————————————————————————————-

import java.util.Arrays;

public class SortPoints

{

public static void main(String[] args)

{

Point[] points = new Point[100];

for (int i = 0; i < points.length; i++)

{

points [i] = new Point(Math.random() * 100, Math.random() *100);

}

System.out.println(“Sort X points”);

Arrays.sort(points);

for (int i = 0; i < points.length; i++)

{

System.out.println(points [i]);

}

System.out.println(“Sort Y points”);

Arrays.sort(points, new CompareY());

for (int i = 0; i < points.length; i++)

{

System.out.println(points [i]);

}

}

public static class Point implements Comparable

{

double x;

double y;

Point(double x, double y)

{

this.x = x;

this.y = y;

}

public int compareTo(Point c2)

{

if(this.x < c2.x)

return – 1;

else if (this.x == c2.x)

{

if(this.y < c2.y)

return – 1;

else if (this.y == c2.y)

return 0;

else

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post