SlideShare a Scribd company logo
Please I am trying to get this code to output in .txt file:
I need your help:
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
// Import the Scanner class to read text files
import java.util.*;
import java.io.*;
public class KMeans {
List<double []> clusterCentroids;
Map<Integer,List<Double>> dataMatrix;
List<double[]> data;
Integer numClusters;
public void writeFile(List<Double> value, File filename) {
try {
FileWriter myWriter = new FileWriter(filename);
myWriter.write(value.toString());
myWriter.close();
System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
public KMeans() {
data = new ArrayList<double []>();
dataMatrix = new LinkedHashMap<>();
}
void readData(String filePath, int n, List<Double> c) {
numClusters = n;
try {
BufferedReader br = new BufferedReader(new FileReader(new File(filePath)));
String line;
int i = 0;
while((line = br.readLine()) != null) {
String [] elem = line.split("s+");
int j = 0;
for(String d : elem) {
if(isCentroid(j, c)) {
this.clusterCentroids.get(i)[j] = ((Double.valueOf(d)));
}
//data.get(i)[j] = ((Double.valueOf(d)));
System.out.println(data.get(j)[i]);
}
System.out.println();
i++;
}
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private boolean isCentroid(int j, List<Double> c) {
for(int i = 0; i < c.size(); i++) {
if(j == c.get(i)) {
return true;
}
}
return false;
}
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
List<Double> centroids = new ArrayList<>();
String filePath = ("C:Usersmamdoeclipse-
workspaceK_projectsrcsynthetic_control_data.txt");
int n = 6;
for(int i=0;i<n;i++) {
Random r = new Random();
centroids.add((double)r.nextInt(600)+1);
}
System.out.println("Initial Clusters Centroids : " + centroids);
KMeans km = new KMeans();
//km.readData(filePath,n,centroids);
//km.calc();
}
}
Please I am trying to get this code to output in -txt file- I need you.pdf
Ad

More Related Content

Similar to Please I am trying to get this code to output in -txt file- I need you.pdf (20)

Random Class & File Handling.pptx
Random Class & File Handling.pptxRandom Class & File Handling.pptx
Random Class & File Handling.pptx
VijalJain3
 
Comments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdfComments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdf
anwarfoot
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
theodorelove43763
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
PRATIKSINHA7304
 
Bhaloo
BhalooBhaloo
Bhaloo
Shumail Haider
 
Code red SUM
Code red SUMCode red SUM
Code red SUM
Shumail Haider
 
Need help on creating code using cart. The output has to show multip.pdf
Need help on creating code using cart. The output has to show multip.pdfNeed help on creating code using cart. The output has to show multip.pdf
Need help on creating code using cart. The output has to show multip.pdf
meerobertsonheyde608
 
Java practical
Java practicalJava practical
Java practical
william otto
 
Write a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdfWrite a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdf
arihantpatna
 
srgoc
srgocsrgoc
srgoc
Gaurav Singh
 
M251_Meeting 7 (Exception Handling and Text IO).ppt
M251_Meeting 7 (Exception Handling and Text IO).pptM251_Meeting 7 (Exception Handling and Text IO).ppt
M251_Meeting 7 (Exception Handling and Text IO).ppt
smartashammari
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
shahidqamar17
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
Alok Kumar
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
anithareadymade
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
alfred4lewis58146
 
Android Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdfAndroid Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdf
feelinggift
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
Manuela Grindei
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
IO and threads Java
IO and threads JavaIO and threads Java
IO and threads Java
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Random Class & File Handling.pptx
Random Class & File Handling.pptxRandom Class & File Handling.pptx
Random Class & File Handling.pptx
VijalJain3
 
Comments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdfComments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdf
anwarfoot
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
theodorelove43763
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
PRATIKSINHA7304
 
Need help on creating code using cart. The output has to show multip.pdf
Need help on creating code using cart. The output has to show multip.pdfNeed help on creating code using cart. The output has to show multip.pdf
Need help on creating code using cart. The output has to show multip.pdf
meerobertsonheyde608
 
Write a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdfWrite a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdf
arihantpatna
 
M251_Meeting 7 (Exception Handling and Text IO).ppt
M251_Meeting 7 (Exception Handling and Text IO).pptM251_Meeting 7 (Exception Handling and Text IO).ppt
M251_Meeting 7 (Exception Handling and Text IO).ppt
smartashammari
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
shahidqamar17
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
Alok Kumar
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
anithareadymade
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
alfred4lewis58146
 
Android Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdfAndroid Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdf
feelinggift
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
Manuela Grindei
 

More from asenterprisestyagi (20)

please I need help- make sure its correct and I will give you ty Matc.pdf
please I need help- make sure its correct and I will give you  ty Matc.pdfplease I need help- make sure its correct and I will give you  ty Matc.pdf
please I need help- make sure its correct and I will give you ty Matc.pdf
asenterprisestyagi
 
please help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdf
please help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdfplease help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdf
please help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdf
asenterprisestyagi
 
Please match the muscles with its correct bony origin- Responses can b.pdf
Please match the muscles with its correct bony origin- Responses can b.pdfPlease match the muscles with its correct bony origin- Responses can b.pdf
Please match the muscles with its correct bony origin- Responses can b.pdf
asenterprisestyagi
 
Please match the muscle with its correct insertion site- Biceps brachi.pdf
Please match the muscle with its correct insertion site- Biceps brachi.pdfPlease match the muscle with its correct insertion site- Biceps brachi.pdf
Please match the muscle with its correct insertion site- Biceps brachi.pdf
asenterprisestyagi
 
Please match the appropriate Career Readiness Competency with their de.pdf
Please match the appropriate Career Readiness Competency with their de.pdfPlease match the appropriate Career Readiness Competency with their de.pdf
Please match the appropriate Career Readiness Competency with their de.pdf
asenterprisestyagi
 
Please make GUI in Eclipse Java Media Rental System Before attempting.pdf
Please make GUI in Eclipse Java Media Rental System Before attempting.pdfPlease make GUI in Eclipse Java Media Rental System Before attempting.pdf
Please make GUI in Eclipse Java Media Rental System Before attempting.pdf
asenterprisestyagi
 
please keep it short and simple Review Sulfide-Indole-Motility medium.pdf
please keep it short and simple Review Sulfide-Indole-Motility medium.pdfplease keep it short and simple Review Sulfide-Indole-Motility medium.pdf
please keep it short and simple Review Sulfide-Indole-Motility medium.pdf
asenterprisestyagi
 
Please help!! An igneous rock forms when melt solidifies- The rock c.pdf
Please help!!   An igneous rock forms when melt solidifies- The rock c.pdfPlease help!!   An igneous rock forms when melt solidifies- The rock c.pdf
Please help!! An igneous rock forms when melt solidifies- The rock c.pdf
asenterprisestyagi
 
Please label and answer all questions please and explain what is 1-.pdf
Please label and answer all questions please and explain what is  1-.pdfPlease label and answer all questions please and explain what is  1-.pdf
Please label and answer all questions please and explain what is 1-.pdf
asenterprisestyagi
 
Please use the same variables and only write the TODO part #!-usr-bi.pdf
Please use the same variables and only write the TODO part   #!-usr-bi.pdfPlease use the same variables and only write the TODO part   #!-usr-bi.pdf
Please use the same variables and only write the TODO part #!-usr-bi.pdf
asenterprisestyagi
 
Please use python to write a script for below- 1- Upload the audio (Pl.pdf
Please use python to write a script for below- 1- Upload the audio (Pl.pdfPlease use python to write a script for below- 1- Upload the audio (Pl.pdf
Please use python to write a script for below- 1- Upload the audio (Pl.pdf
asenterprisestyagi
 
Please Use Java 8 for this project Humans VS Gob.pdf
Please Use Java 8 for this project                       Humans VS Gob.pdfPlease Use Java 8 for this project                       Humans VS Gob.pdf
Please Use Java 8 for this project Humans VS Gob.pdf
asenterprisestyagi
 
Please solving using Alloy Add assort differentTransitionsForFSM- whic.pdf
Please solving using Alloy Add assort differentTransitionsForFSM- whic.pdfPlease solving using Alloy Add assort differentTransitionsForFSM- whic.pdf
Please solving using Alloy Add assort differentTransitionsForFSM- whic.pdf
asenterprisestyagi
 
please solve as soon as possible 1- In a Joint Liability Company the.pdf
please solve as soon as possible  1- In a Joint Liability Company the.pdfplease solve as soon as possible  1- In a Joint Liability Company the.pdf
please solve as soon as possible 1- In a Joint Liability Company the.pdf
asenterprisestyagi
 
Please solve c) and show code using Alloy make sure code can run Add f.pdf
Please solve c) and show code using Alloy make sure code can run Add f.pdfPlease solve c) and show code using Alloy make sure code can run Add f.pdf
Please solve c) and show code using Alloy make sure code can run Add f.pdf
asenterprisestyagi
 
please help- I will upvote- thank you! Q- RESPA specifies percentage r.pdf
please help- I will upvote- thank you! Q- RESPA specifies percentage r.pdfplease help- I will upvote- thank you! Q- RESPA specifies percentage r.pdf
please help- I will upvote- thank you! Q- RESPA specifies percentage r.pdf
asenterprisestyagi
 
please show work (by hand) Translate the following C code to MIPS ass.pdf
please show work (by hand)  Translate the following C code to MIPS ass.pdfplease show work (by hand)  Translate the following C code to MIPS ass.pdf
please show work (by hand) Translate the following C code to MIPS ass.pdf
asenterprisestyagi
 
Please show work- Correct answer is given- Thanks 8- On December 31st.pdf
Please show work- Correct answer is given- Thanks  8- On December 31st.pdfPlease show work- Correct answer is given- Thanks  8- On December 31st.pdf
Please show work- Correct answer is given- Thanks 8- On December 31st.pdf
asenterprisestyagi
 
please solve all of the following What is a -metapopulation-- A group.pdf
please solve all of the following What is a -metapopulation-- A group.pdfplease solve all of the following What is a -metapopulation-- A group.pdf
please solve all of the following What is a -metapopulation-- A group.pdf
asenterprisestyagi
 
Please show work- Correct answer is given- Thanks 5- Kettle Inc- was.pdf
Please show work- Correct answer is given- Thanks  5- Kettle Inc- was.pdfPlease show work- Correct answer is given- Thanks  5- Kettle Inc- was.pdf
Please show work- Correct answer is given- Thanks 5- Kettle Inc- was.pdf
asenterprisestyagi
 
please I need help- make sure its correct and I will give you ty Matc.pdf
please I need help- make sure its correct and I will give you  ty Matc.pdfplease I need help- make sure its correct and I will give you  ty Matc.pdf
please I need help- make sure its correct and I will give you ty Matc.pdf
asenterprisestyagi
 
please help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdf
please help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdfplease help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdf
please help-) Weekly Challenge- There are a lot of blood vessels- Howe (1).pdf
asenterprisestyagi
 
Please match the muscles with its correct bony origin- Responses can b.pdf
Please match the muscles with its correct bony origin- Responses can b.pdfPlease match the muscles with its correct bony origin- Responses can b.pdf
Please match the muscles with its correct bony origin- Responses can b.pdf
asenterprisestyagi
 
Please match the muscle with its correct insertion site- Biceps brachi.pdf
Please match the muscle with its correct insertion site- Biceps brachi.pdfPlease match the muscle with its correct insertion site- Biceps brachi.pdf
Please match the muscle with its correct insertion site- Biceps brachi.pdf
asenterprisestyagi
 
Please match the appropriate Career Readiness Competency with their de.pdf
Please match the appropriate Career Readiness Competency with their de.pdfPlease match the appropriate Career Readiness Competency with their de.pdf
Please match the appropriate Career Readiness Competency with their de.pdf
asenterprisestyagi
 
Please make GUI in Eclipse Java Media Rental System Before attempting.pdf
Please make GUI in Eclipse Java Media Rental System Before attempting.pdfPlease make GUI in Eclipse Java Media Rental System Before attempting.pdf
Please make GUI in Eclipse Java Media Rental System Before attempting.pdf
asenterprisestyagi
 
please keep it short and simple Review Sulfide-Indole-Motility medium.pdf
please keep it short and simple Review Sulfide-Indole-Motility medium.pdfplease keep it short and simple Review Sulfide-Indole-Motility medium.pdf
please keep it short and simple Review Sulfide-Indole-Motility medium.pdf
asenterprisestyagi
 
Please help!! An igneous rock forms when melt solidifies- The rock c.pdf
Please help!!   An igneous rock forms when melt solidifies- The rock c.pdfPlease help!!   An igneous rock forms when melt solidifies- The rock c.pdf
Please help!! An igneous rock forms when melt solidifies- The rock c.pdf
asenterprisestyagi
 
Please label and answer all questions please and explain what is 1-.pdf
Please label and answer all questions please and explain what is  1-.pdfPlease label and answer all questions please and explain what is  1-.pdf
Please label and answer all questions please and explain what is 1-.pdf
asenterprisestyagi
 
Please use the same variables and only write the TODO part #!-usr-bi.pdf
Please use the same variables and only write the TODO part   #!-usr-bi.pdfPlease use the same variables and only write the TODO part   #!-usr-bi.pdf
Please use the same variables and only write the TODO part #!-usr-bi.pdf
asenterprisestyagi
 
Please use python to write a script for below- 1- Upload the audio (Pl.pdf
Please use python to write a script for below- 1- Upload the audio (Pl.pdfPlease use python to write a script for below- 1- Upload the audio (Pl.pdf
Please use python to write a script for below- 1- Upload the audio (Pl.pdf
asenterprisestyagi
 
Please Use Java 8 for this project Humans VS Gob.pdf
Please Use Java 8 for this project                       Humans VS Gob.pdfPlease Use Java 8 for this project                       Humans VS Gob.pdf
Please Use Java 8 for this project Humans VS Gob.pdf
asenterprisestyagi
 
Please solving using Alloy Add assort differentTransitionsForFSM- whic.pdf
Please solving using Alloy Add assort differentTransitionsForFSM- whic.pdfPlease solving using Alloy Add assort differentTransitionsForFSM- whic.pdf
Please solving using Alloy Add assort differentTransitionsForFSM- whic.pdf
asenterprisestyagi
 
please solve as soon as possible 1- In a Joint Liability Company the.pdf
please solve as soon as possible  1- In a Joint Liability Company the.pdfplease solve as soon as possible  1- In a Joint Liability Company the.pdf
please solve as soon as possible 1- In a Joint Liability Company the.pdf
asenterprisestyagi
 
Please solve c) and show code using Alloy make sure code can run Add f.pdf
Please solve c) and show code using Alloy make sure code can run Add f.pdfPlease solve c) and show code using Alloy make sure code can run Add f.pdf
Please solve c) and show code using Alloy make sure code can run Add f.pdf
asenterprisestyagi
 
please help- I will upvote- thank you! Q- RESPA specifies percentage r.pdf
please help- I will upvote- thank you! Q- RESPA specifies percentage r.pdfplease help- I will upvote- thank you! Q- RESPA specifies percentage r.pdf
please help- I will upvote- thank you! Q- RESPA specifies percentage r.pdf
asenterprisestyagi
 
please show work (by hand) Translate the following C code to MIPS ass.pdf
please show work (by hand)  Translate the following C code to MIPS ass.pdfplease show work (by hand)  Translate the following C code to MIPS ass.pdf
please show work (by hand) Translate the following C code to MIPS ass.pdf
asenterprisestyagi
 
Please show work- Correct answer is given- Thanks 8- On December 31st.pdf
Please show work- Correct answer is given- Thanks  8- On December 31st.pdfPlease show work- Correct answer is given- Thanks  8- On December 31st.pdf
Please show work- Correct answer is given- Thanks 8- On December 31st.pdf
asenterprisestyagi
 
please solve all of the following What is a -metapopulation-- A group.pdf
please solve all of the following What is a -metapopulation-- A group.pdfplease solve all of the following What is a -metapopulation-- A group.pdf
please solve all of the following What is a -metapopulation-- A group.pdf
asenterprisestyagi
 
Please show work- Correct answer is given- Thanks 5- Kettle Inc- was.pdf
Please show work- Correct answer is given- Thanks  5- Kettle Inc- was.pdfPlease show work- Correct answer is given- Thanks  5- Kettle Inc- was.pdf
Please show work- Correct answer is given- Thanks 5- Kettle Inc- was.pdf
asenterprisestyagi
 
Ad

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho..."Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
ruslana1975
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho..."Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
ruslana1975
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Ad

Please I am trying to get this code to output in -txt file- I need you.pdf

  • 1. Please I am trying to get this code to output in .txt file: I need your help: import java.io.File; // Import the File class import java.io.FileNotFoundException; // Import this class to handle errors // Import the Scanner class to read text files import java.util.*; import java.io.*; public class KMeans { List<double []> clusterCentroids; Map<Integer,List<Double>> dataMatrix; List<double[]> data; Integer numClusters; public void writeFile(List<Double> value, File filename) { try { FileWriter myWriter = new FileWriter(filename); myWriter.write(value.toString()); myWriter.close(); System.out.println("Successfully wrote to the file."); } catch (IOException e) { System.out.println("An error occurred."); e.printStackTrace(); } } public KMeans() { data = new ArrayList<double []>(); dataMatrix = new LinkedHashMap<>(); } void readData(String filePath, int n, List<Double> c) { numClusters = n; try { BufferedReader br = new BufferedReader(new FileReader(new File(filePath))); String line; int i = 0; while((line = br.readLine()) != null) { String [] elem = line.split("s+"); int j = 0; for(String d : elem) {
  • 2. if(isCentroid(j, c)) { this.clusterCentroids.get(i)[j] = ((Double.valueOf(d))); } //data.get(i)[j] = ((Double.valueOf(d))); System.out.println(data.get(j)[i]); } System.out.println(); i++; } br.close(); } catch (IOException ex) { ex.printStackTrace(); } } private boolean isCentroid(int j, List<Double> c) { for(int i = 0; i < c.size(); i++) { if(j == c.get(i)) { return true; } } return false; } public static void main(String [] args) { Scanner sc = new Scanner(System.in); List<Double> centroids = new ArrayList<>(); String filePath = ("C:Usersmamdoeclipse- workspaceK_projectsrcsynthetic_control_data.txt"); int n = 6; for(int i=0;i<n;i++) { Random r = new Random(); centroids.add((double)r.nextInt(600)+1); } System.out.println("Initial Clusters Centroids : " + centroids); KMeans km = new KMeans(); //km.readData(filePath,n,centroids); //km.calc(); } }
  翻译: