I need to randomly split the data in a 2 dimensional array. The data is being read from a txt file. The data must be split 75% and 25%. After the split I need to calculate the euclidean distance.
import java.io.*;
import java.util.Scanner;
public class Question {
public static void main(String args[ ]) throws IOException
{
int i = 0;
Scanner sc = new Scanner(new File("C://file.txt"));
float []c = new float[10000];
while( sc.hasNext()){
c[i]=sc.nextFloat();
i ++;
}
int a =(int)(i*0.75);
System.out.println("a="+a);
int b = i-a;
System.out.println("b="+b);
int a1=a;
int b1 =b;
float [][]mas = new float[10000][2];
for(int j = 0;j<=i;j++){
if(Math.random()>0.75){
if(b>=0){
mas[b][1]=c[j];
b--;
}
else if(a>=0){mas[a][0]=c[j];
a--;
}
}
else{
if(a>=0){
mas[a][0]=c[j];
a--;
}
else if(b>=0){
mas[b][1]=c[j];
b--;}
}
}
float s =0;
for (int n =0;n<=a1+1;n++){
System.out.print (mas[n][0]);
System.out.println(" "+mas[n][1]);
s+=(mas[n][0]-mas[n][1])*(mas[n][0]-mas[n][1]);
}
System.out.print (Math.sqrt(s));//euclidean distance
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF