Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

In this page you can find the example usage for java.lang Integer parseInt.

Prototype

public static int parseInt(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal integer.

Usage

From source file:ExecutorHttpd.java

public static void main(String argv[]) throws Exception {
    new ExecutorHttpd().start(Integer.parseInt(argv[0]));
}

From source file:cn.wanghaomiao.seimi.boot.Run.java

public static void main(String[] args) {
    Seimi s = new Seimi();
    if (ArrayUtils.isNotEmpty(args)) {
        if (args[0].matches("\\d+")) {
            int port = Integer.parseInt(args[0]);
            if (args.length > 1) {
                s.startWithHttpd(port, ArrayUtils.subarray(args, 1, args.length));
            } else {
                s.startAllWithHttpd(port);
            }//from ww w . jav a 2 s . co m
        } else {
            s.start(args);
        }
    } else {
        s.startAll();
    }
}

From source file:jp.ac.titech.cs.se.sparesort.Main.java

public static void main(String[] args) throws Exception {
    SequenceDatabase<String> sdb = new SequenceDatabase<String>();

    int minSup = Integer.parseInt(args[0]);
    for (int i = 1; i < args.length; i++) {
        sdb.addSequence(loadStringListFromFile(args[i]));
    }/*from  www.ja  va  2s.  c  om*/

    Map<List<String>, Integer> result = sdb.mineFrequentClosedSequences(minSup);
    for (Map.Entry<List<String>, Integer> entry : result.entrySet()) {
        System.out.println(entry.getKey() + ":" + entry.getValue());
    }
}

From source file:com.spotify.annoy.jni.base.Benchmark.java

public static void main(String[] args) throws IOException, InterruptedException {
    String annPath = args[0];/*  w  ww  . ja va  2 s .c o  m*/
    Integer dim = Integer.parseInt(args[1]);
    String queryFile = args[2];
    Integer nnsCount = Integer.parseInt(args[3]);
    runBenchmark(annPath, dim, queryFile, nnsCount);
}

From source file:Sieve.java

public static void main(String[] args) {
    // We will compute all primes less than the value specified on the
    // command line, or, if no argument, all primes less than 100.
    int max = 100; // Assign a default value
    try {//w ww .  jav a 2 s.  com
        max = Integer.parseInt(args[0]);
    } // Parse user-supplied arg
    catch (Exception e) {
    } // Silently ignore exceptions.

    // Create an array that specifies whether each number is prime or not.
    boolean[] isprime = new boolean[max + 1];

    // Assume that all numbers are primes, until proven otherwise.
    for (int i = 0; i <= max; i++)
        isprime[i] = true;

    // However, we know that 0 and 1 are not primes. Make a note of it.
    isprime[0] = isprime[1] = false;

    // To compute all primes less than max, we need to rule out
    // multiples of all integers less than the square root of max.
    int n = (int) Math.ceil(Math.sqrt(max)); // See java.lang.Math class

    // Now, for each integer i from 0 to n:
    //   If i is a prime, then none of its multiples are primes,
    //   so indicate this in the array. If i is not a prime, then
    //   its multiples have already been ruled out by one of the
    //   prime factors of i, so we can skip this case.
    for (int i = 0; i <= n; i++) {
        if (isprime[i]) // If i is a prime,
            for (int j = 2 * i; j <= max; j = j + i)
                // loop through multiples
                isprime[j] = false; // they are not prime.
    }

    // Now go look for the largest prime:
    int largest;
    for (largest = max; !isprime[largest]; largest--)
        ; // empty loop body

    // Output the result
    System.out.println("The largest prime less than or equal to " + max + " is " + largest);
}

From source file:javaapplicationclientrest.JavaApplicationClientRest.java

/**
 * @param args the command line arguments
 *///from w  w w  . ja va  2 s .c  o m
public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    ControllerCliente controller = new ControllerCliente();
    while (true) {
        controller.getMenu();

        int op = 0;
        try {
            op = Integer.parseInt(input.nextLine());
        } catch (Exception e) {
        }

        //input.nextLine();
        switch (op) {
        case 1:
            controller.listarNoticias();
            break;
        case 2:

            System.out.println("Informe o titulo: ");
            String titulo = input.nextLine();
            if (titulo.trim().equals("")) {
                System.out.println("Ttulo invlido");
                break;
            }
            System.out.println("Informe o autor: ");
            String autor = input.nextLine();
            if (autor.trim().equals("")) {
                System.out.println("Autor invlido");
                break;
            }
            System.out.println("Informe o Conteudo: ");
            String conteudo = input.nextLine();
            if (conteudo.trim().equals("")) {
                System.out.println("Conteudo invlido");
                break;
            }
            //System.out.println(id);
            controller.cadastrarNoticia(titulo, autor, conteudo);
            break;

        case 3:

            try {
                System.out.println("Informe o id da notcia a ser removida: ");
                String idN = input.nextLine();
                Integer.parseInt(idN);
                controller.removerNoticia(idN);
            } catch (Exception e) {
                System.out.println("Numero invlido");
            }
            break;
        case 4:
            try {
                System.out.println("Informe o Id da notcia desejada:");
                String idN = input.nextLine();
                Integer.parseInt(idN);
                controller.getNoticia(idN);
            } catch (Exception e) {
                System.out.println("Id invlido");
                break;
            }
            break;
        case 5:
            try {
                System.out.println("Informe o Id da notcia para ser atualizada:");
                String idA = input.nextLine();
                Integer.parseInt(idA);
                System.out.println("Informe o novo titulo: ");
                String tituloN = input.nextLine();
                controller.atualizarNoticia(idA, tituloN);
            } catch (Exception e) {
                System.out.println("Id invlido");
            }
            break;

        default:
            System.out.println("Opo invlida. Escolha uma opo novamente");
            break;
        } // End switch
    } // End while

}

From source file:challenge302.intermediate.ASCIIHistogramMaker.java

public static void main(String[] args) {
    String inFile = "/data/challenge302intermediate.txt";

    //        ArrayList<int[]> graphData = new ArrayList<int[]>();
    ArrayList<String> input = new ChallengeInput().getInputByLines(ASCIIHistogramMaker.class, inFile);
    //take first line as the chart bounds and create new BarChart with those bounds
    IntBasedBarChart chart = new IntBasedBarChart(input.remove(0).split(" "));

    //take next line as the number of chart elements
    int size = Integer.parseInt(input.remove(0));

    for (int i = 0; i < size; i++) {
        //            System.out.println("Parsing: graph data line=\""+input.get(i)+"\"");
        chart.addData(stringArraytoIntArray(input.get(i).split(" ")));
    } //end adding all lines

    printChart(chart, size);/*from www  . j  a  v a 2s  .com*/

}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.TextsResumeToJson.java

public static void main(String[] args) throws IOException {
    String host = args[0];/*from  www. j a v  a2 s  .  com*/
    int port = Integer.parseInt(args[1]);
    Jedis jedis = new Jedis(host, port, 20000);

    String[] text_keys = jedis.keys("hash_id_*").toArray(new String[0]);

    for (int i = 0; i < text_keys.length; ++i) {
        JSONArray resume = new JSONArray();
        String[] split_resume_name = text_keys[i].split("_");
        String id = split_resume_name[split_resume_name.length - 1];

        JSONObject text = new JSONObject();
        text.put("id", id);
        text.put("tittle", jedis.hget(text_keys[i], "tittle"));
        text.put("text", jedis.hget(text_keys[i], "text"));

        resume.add(text);

        saveResults(resume, id);
    }
    jedis.disconnect();
}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java

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

    String host = args[0];/*w  w  w. j ava 2 s  .c  o  m*/
    int port = Integer.parseInt(args[1]);
    Jedis jedis = new Jedis(host, port, 20000);

    // Cluster to binary tree visualitzation
    Map<String, String> attr_cluster = jedis.hgetAll("ClusterBinaryTree-Arrel");
    String cluster_name = attr_cluster.get("cluster_ids_name");

    JSONObject cluster;
    if (!cluster_name.equals("cluster_splited")) {
        cluster = new JSONObject();
        cluster.put("name", "arrel");
    } else {
        String id_left_centroid = attr_cluster.get("id_left_centroid");
        String id_right_centroid = attr_cluster.get("id_right_centroid");

        String hash_left = attr_cluster.get("hash_left");
        String hash_right = attr_cluster.get("hash_right");

        cluster = new JSONObject();
        cluster.put("name", "arrel");
        cluster.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis,
                id_right_centroid, hash_right));
    }
    jedis.disconnect();

    Writer out = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream("data_toVisualize/cluster.json"), "UTF-8"));
    try {
        out.write(cluster.toJSONString());
    } finally {
        out.close();
    }
}

From source file:HttpMirror.java

public static void main(String args[]) {
    try {/*from  ww w  .  ja va 2s.  co  m*/
        // Get the port to listen on
        int port = Integer.parseInt(args[0]);
        // Create a ServerSocket to listen on that port.
        ServerSocket ss = new ServerSocket(port);
        // Now enter an infinite loop, waiting for & handling connections.
        for (;;) {
            // Wait for a client to connect. The method will block;
            // when it returns the socket will be connected to the client
            Socket client = ss.accept();

            // Get input and output streams to talk to the client
            BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
            PrintWriter out = new PrintWriter(client.getOutputStream());

            // Start sending our reply, using the HTTP 1.1 protocol
            out.print("HTTP/1.1 200 \r\n"); // Version & status code
            out.print("Content-Type: text/plain\r\n"); // The type of data
            out.print("Connection: close\r\n"); // Will close stream
            out.print("\r\n"); // End of headers

            // Now, read the HTTP request from the client, and send it
            // right back to the client as part of the body of our
            // response. The client doesn't disconnect, so we never get
            // an EOF. It does sends an empty line at the end of the
            // headers, though. So when we see the empty line, we stop
            // reading. This means we don't mirror the contents of POST
            // requests, for example. Note that the readLine() method
            // works with Unix, Windows, and Mac line terminators.
            String line;
            while ((line = in.readLine()) != null) {
                if (line.length() == 0)
                    break;
                out.print(line + "\r\n");
            }

            // Close socket, breaking the connection to the client, and
            // closing the input and output streams
            out.close(); // Flush and close the output stream
            in.close(); // Close the input stream
            client.close(); // Close the socket itself
        } // Now loop again, waiting for the next connection
    }
    // If anything goes wrong, print an error message
    catch (Exception e) {
        System.err.println(e);
        System.err.println("Usage: java HttpMirror <port>");
    }
}