-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKmean.java
More file actions
47 lines (45 loc) · 870 Bytes
/
Kmean.java
File metadata and controls
47 lines (45 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.*;
import java.math.*;
class Kmean
{
public static void main(String args[])
{
int n,i,j,k;
Scanner sc=new Scanner(System.in);
System.out.println("enter the no of points");
n=sc.nextInt();
double a[][]=new double[n][2];
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
System.out.println("Enter the value for"+i+","+j+":");
a[i][j]=sc.nextDouble();
}
}
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
Double x[][]=new Double[n][n];
for(i=0;i<n;i++)
{
for(k=0;k<n;k++)
{
x[i][k]=Math.sqrt(Math.pow((a[i][0]-a[k][0]),2)+Math.pow((a[i][1]-a[k][1]),2));
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(x[i][j]+" \t\t\t\t\t");
}
System.out.println();
}
}
}