Example usage for java.lang Double parseDouble

List of usage examples for java.lang Double parseDouble

Introduction

In this page you can find the example usage for java.lang Double parseDouble.

Prototype

public static double parseDouble(String s) throws NumberFormatException 

Source Link

Document

Returns a new double initialized to the value represented by the specified String , as performed by the valueOf method of class Double .

Usage

From source file:Main.java

public static void main(String[] args) {
    String str = "This is a 23.4.123 test.";
    String[] s = str.split(" ");
    Pattern p = Pattern.compile("(\\d)+\\.(\\d)+");
    double d;/*from w ww .  ja va 2  s  . co  m*/
    for (int i = 0; i < s.length; i++) {
        Matcher m = p.matcher(s[i]);
        while (m.find()) {
            d = Double.parseDouble(m.group());
            System.out.println(d);
        }
    }
}

From source file:Main.java

public static void main(String args[]) {
    SpinnerNumberModel model = new SpinnerNumberModel(0.0, -1000.0, 1000.0, 0.1);
    JSpinner s = new JSpinner(model);
    JSpinner.NumberEditor editor = new JSpinner.NumberEditor(s);
    s.setEditor(editor);//  w w w.jav  a 2s .  c  o  m
    JTextField stepText = new JTextField(10);
    JButton bStepSet = new JButton("Set Step");
    bStepSet.addActionListener(e -> {
        Double val = Double.parseDouble(stepText.getText().trim());
        model.setStepSize(val);
    });
    JFrame f = new JFrame();
    Container c = f.getContentPane();
    c.add(s);
    JPanel southPanel = new JPanel();
    southPanel.add(stepText);
    southPanel.add(bStepSet);
    c.add(southPanel, BorderLayout.SOUTH);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:es.cnio.bioinfo.bicycle.BinomialAnnotator.java

public static void main(String[] args) throws IOException, MathException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    double p = Double.parseDouble(args[0]);
    String line = null;/*w w w.j  a  v a 2 s.co m*/

    while ((line = in.readLine()) != null) {

        String[] tokens = line.split("\t");
        int reads = Integer.parseInt(tokens[5]);
        int cCount = Integer.parseInt(tokens[4]);
        BinomialDistribution binomial = new BinomialDistributionImpl(reads, p);
        double pval = (reads == 0) ? 1.0d : (1.0d - binomial.cumulativeProbability(cCount - 1));
        if (System.out.checkError()) {
            System.exit(1);
        }
        System.out.println(line + "\t" + pval);

    }
}

From source file:edu.berkeley.compbio.phyloutils.NearestNodeFinder.java

public static void main(String[] argv) throws IOException, NoSuchNodeException {
    //service.setGreengenesRawFilename(argv[0]);
    service.setHugenholtzFilename(argv[0]);
    //service.setSynonymService(NcbiTaxonomyClient.getInstance());
    service.init();/*from  w  w  w. ja  va  2s.  c o  m*/

    final int[] targetIds = IntArrayReader.read(argv[1]);
    int[] queryIds = IntArrayReader.read(argv[2]);
    final double minDistance = Double.parseDouble(argv[3]); // implement leave-one-out at any level

    Map<Integer, Double> results = Parallel.map(new ArrayIterator(queryIds), new Function<Integer, Double>() {
        public Double apply(Integer queryId) {
            try {
                double best = Double.MAX_VALUE;
                for (int targetId : targetIds) {
                    double d = service.minDistanceBetween(queryId, targetId);
                    if (d >= minDistance) {
                        best = Math.min(best, d);
                    }
                }
                return best;
            } catch (NoSuchNodeException e) {
                throw new Error(e);
            }
        }
    });

    String outfileName = argv[4];
    PrintWriter out = new PrintWriter(outfileName);
    out.println("id\tdist");

    for (Map.Entry<Integer, Double> entry : results.entrySet()) {
        out.println(entry.getKey() + "\t" + entry.getValue());
    }
    out.close();
}

From source file:History.PieChart_DB.java

public static void main(String[] args) throws Exception {

    String mobilebrands[] = { "IPhone 5s", "SamSung Grand", "MotoG", "Nokia Lumia" };
    int statOfRepair = 0;
    java.util.Date now = new java.util.Date();
    String adminDate = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate();
    /* Create MySQL Database Connection */
    Class.forName("com.mysql.jdbc.Driver");
    Connection connect = ConnectDatabase.connectDb("win", "win016");

    Statement statement = connect.createStatement();
    ResultSet resultSet = statement
            .executeQuery("SELECT COUNT(transID) AS statRepair FROM `Transaction` WHERE dateTime LIKE \'"
                    + adminDate + "%\' AND action LIKE 'Repair'");
    DefaultPieDataset dataset = new DefaultPieDataset();

    while (resultSet.next()) {
        dataset.setValue(resultSet.getString("statRepair"),
                Double.parseDouble(resultSet.getString("unit_sale")));
    }/*from   ww  w .j a v  a2  s. com*/

    JFreeChart chart = ChartFactory.createPieChart("History", // chart title           
            dataset, // data           
            true, // include legend          
            true, false);

    int width = 560; /* Width of the image */
    int height = 370; /* Height of the image */
    File pieChart = new File("Pie_Chart.jpeg");
    ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height);
}

From source file:com.algoTrader.starter.SimulationStarter.java

public static void main(String[] args) throws ConvergenceException, FunctionEvaluationException {

    ServiceLocator.serverInstance().init("beanRefFactorySimulation.xml");

    if ("simulateWithCurrentParams".equals(args[0])) {

        ServiceLocator.serverInstance().getSimulationService().simulateWithCurrentParams();

    } else if ("optimizeSingleParamLinear".equals(args[0])) {

        String strategyName = args[1];
        for (int i = 2; i < args.length; i++) {
            String[] params = args[i].split(":");
            String parameter = params[0];
            double min = Double.parseDouble(params[1]);
            double max = Double.parseDouble(params[2]);
            double increment = Double.parseDouble(params[3]);

            ServiceLocator.serverInstance().getSimulationService().optimizeSingleParamLinear(strategyName,
                    parameter, min, max, increment);

        }//  w  w w. ja  v a  2 s.c o m
    }

    ServiceLocator.serverInstance().shutdown();
}

From source file:PCC.java

/**
 * @param args the command line arguments
 * @throws java.io.IOException//www  .ja  va 2 s  .  co m
 */

public static void main(String[] args) throws IOException {
    // TODO code application logic here

    PearsonsCorrelation corel = new PearsonsCorrelation();
    PCC method = new PCC();
    ArrayList<String> name = new ArrayList<>();
    Multimap<String, String> genes = ArrayListMultimap.create();
    BufferedWriter bw = new BufferedWriter(new FileWriter(args[1]));
    BufferedReader br = new BufferedReader(new FileReader(args[0]));
    String str;
    while ((str = br.readLine()) != null) {
        String[] a = str.split("\t");
        name.add(a[0]);
        for (int i = 1; i < a.length; i++) {
            genes.put(a[0], a[i]);
        }
    }
    for (String key : genes.keySet()) {
        double[] first = new double[genes.get(key).size()];
        int element1 = 0;
        for (String value : genes.get(key)) {
            double d = Double.parseDouble(value);
            first[element1] = d;
            element1++;
        }
        for (String key1 : genes.keySet()) {
            if (!key.equals(key1)) {
                double[] second = new double[genes.get(key1).size()];
                int element2 = 0;
                for (String value : genes.get(key1)) {
                    double d = Double.parseDouble(value);
                    second[element2] = d;
                    element2++;

                }
                double corrlation = corel.correlation(first, second);
                if (corrlation > 0.5) {
                    bw.write(key + "\t" + key1 + "\t" + corrlation + "\t"
                            + method.pvalue(corrlation, second.length) + "\n");
                }
            }
        }
    }
    br.close();
    bw.close();
}

From source file:akori.Impact.java

static public void main(String[] args) throws IOException {
    String PATH = "E:\\Trabajos\\AKORI\\datosmatrizgino\\";
    String PATHIMG = "E:\\NetBeansProjects\\AKORI\\Proccess_1\\ImagesPages\\";
    for (int i = 1; i <= 32; ++i) {
        for (int k = 1; k <= 15; ++k) {
            System.out.println("Matrix " + i + "-" + k);
            BufferedImage img = null;
            try {
                img = ImageIO.read(new File(PATHIMG + i + ".png"));
            } catch (IOException ex) {
                ex.getStackTrace();/*w ww.  java 2  s  .  co m*/
            }

            int ymax = img.getHeight();
            int xmax = img.getWidth();

            double[][] imagen = new double[ymax][xmax];

            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(PATH + i + "-" + k + ".txt"));
            } catch (FileNotFoundException ex) {
                ex.getStackTrace();
            }

            String linea;
            ArrayList<String> lista = new ArrayList<String>();
            HashMap<String, String> lista1 = new HashMap<String, String>();
            try {
                for (int j = 0; (linea = in.readLine()) != null; ++j) {
                    String[] datos = linea.split(",");
                    int x = (int) Double.parseDouble(datos[1]);
                    int y = (int) Double.parseDouble(datos[2]);
                    if (x >= xmax || y >= ymax || x <= 0 || y <= 0) {
                        continue;
                    }
                    lista.add(x + "," + y);
                }
            } catch (Exception ex) {
                ex.getStackTrace();
            }

            try {
                in.close();
            } catch (IOException ex) {
                ex.getStackTrace();
            }

            Iterator iter = lista.iterator();
            int[][] matrix = new int[lista.size()][2];

            for (int j = 0; iter.hasNext(); ++j) {
                String xy = (String) iter.next();
                String[] datos = xy.split(",");
                matrix[j][0] = Integer.parseInt(datos[0]);
                matrix[j][1] = Integer.parseInt(datos[1]);
            }

            for (int j = 0; j < matrix.length; ++j) {

                int std = 50;
                int x = matrix[j][0];
                int y = matrix[j][1];
                imagen[y][x] += 1;
                double aux;
                normalMatrix(imagen, y, x, std);

            }

            FileWriter fw = new FileWriter(PATH + "Matrix" + i + "-" + k + ".txt");
            BufferedWriter bw = new BufferedWriter(fw);
            for (int j = 0; j < imagen.length; ++j) {
                for (int t = 0; t < imagen[j].length; ++t) {
                    if (t + 1 == imagen[j].length)
                        bw.write(imagen[j][t] + "");
                    else
                        bw.write(imagen[j][t] + ",");
                }
                bw.write("\n");
            }
            bw.close();
        }
    }
}

From source file:AverageCost.java

public static void main(String[] args) throws FileNotFoundException, IOException {
    //Directory of the n files
    String directory_path = "/home/gauss/rgrunitzki/Dropbox/Profissional/UFRGS/Doutorado/Artigo TRI15/SF Experiments/IQ-Learning/";
    BufferedReader reader = null;
    //Line to analyse
    String line = "";
    String csvDivisor = ";";
    int totalLines = 1002;
    int totalRows = 532;

    String filesToRead[] = new File(directory_path).list();
    Arrays.sort(filesToRead);/*  ww  w  . j a va  2 s  .  c  om*/
    System.out.println(filesToRead.length);

    List<List<DescriptiveStatistics>> summary = new ArrayList<>();

    for (int i = 0; i <= totalLines; i++) {
        summary.add(new ArrayList<DescriptiveStatistics>());
        for (int j = 0; j <= totalRows; j++) {
            summary.get(i).add(new DescriptiveStatistics());
        }
    }

    //reads all files
    for (String file : filesToRead) {
        reader = new BufferedReader(new FileReader(directory_path + file));
        int lineCounter = 0;
        //reads all file's line
        while ((line = reader.readLine()) != null) {
            if (lineCounter > 0) {
                String[] rows = line.trim().split(csvDivisor);
                //reads all line's row
                for (int r = 0; r < rows.length; r++) {
                    summary.get(lineCounter).get(r).addValue(Double.parseDouble(rows[r]));
                }
            }
            lineCounter++;
        }

        //System.out.println(file.split("/")[file.split("/").length - 1] + csvDivisor + arithmeticMean(avgCost) + csvDivisor + standardDeviation(avgCost));
    }

    //generate mean and standard deviation;
    for (List<DescriptiveStatistics> summaryLines : summary) {
        System.out.println();
        for (DescriptiveStatistics summaryLineRow : summaryLines) {
            System.out.print(summaryLineRow.getMean() + ";" + summaryLineRow.getStandardDeviation() + ";");
        }
    }
}

From source file:main.java.gov.wa.wsdot.candidate.evaluation.App.java

public static void main(String[] args) {

    System.out.println("Hello WSDOT ITS 3 Candidate!");
    System.out.println("Hello WSDOT ITS 3 Interviewers!");

    if (args.length != 3) {
        System.out.println("Parameters: latitude longitude radius\n");
    } else {/*from  w w w  .  j  a v a2 s .  c  o  m*/

        App app = new App(Double.parseDouble(args[0]), Double.parseDouble(args[1]), Integer.parseInt(args[2]));
        try {
            app.run();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}