//Just saw a complaint about this problem and i wanted to offer a simple solution to this problem
//Its a self adjusting alg. feel free to post anywhere else, but cite me
//https://www.technologyreview.com/2020/12/04/1013068/algorithms-create-a-poverty-trap-lawyers-fight-back/?utm_source=pocket-newtab
//Citations: Mkyong, Aman Singh, javainterviewpoint, programiz
import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.lang.*;
public class SlfChkAlg{
private static final String COMMA_DELIMITER = ",";
public static void main(String[] args) {
final String CSV_FILE_PATH = "./result.csv";
Scanner scan=new File("name of the file");
String csvFile = "/Users/mkyong/csv/country.csv";
String line = "";
String cvsSplitBy = ",";
writeDataLineByLine(CSV_FILE_PATH);
//rolling avg + std
for(i=0;i<param.length;i++){System.out.println(i);
sum+=param[i];return(sum);avg=sum/param.length;
std+=Math.pow(i-avg,2);return Math.sqrt(std/param.length);}}
public static void writeDataLineByLine(String csvFile)
{
// first create file object for file placed at location
// specified by csvFile
File file = new File(csvFile);
try {
// create FileWriter object with file as parameter
FileWriter outputfile = new FileWriter(file);
// create CSVWriter object filewriter object as parameter
CSVWriter writer = new CSVWriter(outputfile);
// adding header to csv
String[] header = { "a", "b", "c" };
writer.writeNext(header);
}catch(FileNotFoundException g){g.printStackTrace();}
try {
//Get the scanner instance
//Use Delimiter as COMMA
scanner.useDelimiter(COMMA_DELIMITER);
while(scan.hasNext()){System.out.print(scan.next()+" ");}}
catch (FileNotFoundException fe) {fe.printStackTrace();}
// add data to csv
CSVWriter writer = new CSVWriter(outputfile, ';',
CSVWriter.NO_QUOTE_CHARACTER,
CSVWriter.DEFAULT_ESCAPE_CHARACTER,
CSVWriter.DEFAULT_LINE_END);
// create a List which contains Data
List<String[]> data = new ArrayList<String[]>();
System.out.println("Enter no of rows");
int noOfRow = Integer.parseInt(sc.nextLine());
System.out.println("Enter Data");
for (int i = 0; i < noOfRow; i++) {
String row = scan.nextLine();
String[] rowdata = row.split(" ");
data.add(rowdata);
}
writer.writeAll(data);
// closing writer connection
writer.close();
}
try {
BufferedReader br = new BufferedReader(new FileReader(csvFile))
while ((line = br.readLine()) != null) {
// use comma as separator
Int[]param=new Int[i];param = line.split(cvsSplitBy);
System.out.println("a" + param[0] + ",b" + param[1] + ",c" + param[2]);}
} catch (IOException e) { e.printStackTrace();} }}
YOU ARE READING
My Prog Adventures
SpiritualI am also a programmer. I have been intending to post some of my scripts on here. I can teach math and programming, please reach out to me in conversations, my messages on here isnt working.
