Example usage for java.util Scanner nextInt

List of usage examples for java.util Scanner nextInt

Introduction

In this page you can find the example usage for java.util Scanner nextInt.

Prototype

public int nextInt() 

Source Link

Document

Scans the next token of the input as an int .

Usage

From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MzXMLToDTAConverterStreamingImplTest.java

@Test(groups = "unit")
public void readw() {
    /*//from w  w  w .j  a  v  a2  s . c  o m
    final Random random = new Random();
    int count = 5000;
    double[] peaks = new double[count];
    for(int i =0; i < count; i++) {
      peaks[i] = random.nextDouble();
    }
            
    System.out.println(new String(Base64.encodeBase64(ConversionUtils.doubles2bytes(peaks))));
    */
    final MzXMLToDTAConverterStreamingImpl converter = new MzXMLToDTAConverterStreamingImpl();
    DTAList dtaList;
    InputStream mzxmlStream;
    mzxmlStream = ProteomicsTests.getResourceAsStream("readw.mzXML");
    try {
        dtaList = converter.mzxmlToDTA(mzxmlStream, null);
        double[] contents78charge2 = null, contents78charge3 = null;
        for (DTAList.Entry entry : dtaList) {
            if (entry.getName().matches(".*0*78\\.0*78\\.2\\.dta$")) {
                assert contents78charge2 == null;
                contents78charge2 = DTAUtils.readDtaDoublePairs(entry.getContents());
            }
            if (entry.getName().matches(".*0*78\\.0*78\\.3\\.dta$")) {
                assert contents78charge3 == null;
                contents78charge3 = DTAUtils.readDtaDoublePairs(entry.getContents());
            }
            if (entry.getName().matches(".*0*1993\\.0*1993\\.1\\.dta$")) {
                final double[] values = DTAUtils.readDtaDoublePairs(entry.getContents());
                final Scanner scanner = new Scanner(new ByteArrayInputStream(entry.getContents()));
                assert MathUtils.equals(scanner.nextDouble(), 1515.390000);
                assert scanner.nextInt() == 1;
                assert Math.abs(662.267334 - values[0]) < .01 : values[0];
                assert Math.abs(4.004042 - values[values.length - 1]) < .01;
            }
        }
        assert contents78charge2 != null;
        assert contents78charge3 != null;
        assert contents78charge2.length == contents78charge3.length;
        for (int i = 2; i < contents78charge2.length; i++) {
            assert MathUtils.equals(contents78charge2[i], contents78charge3[i]);
        }
    } finally {
        IO_UTILS.closeQuietly(mzxmlStream);
    }
}

From source file:phonegraph.PhoneGraph.java

public void CreatedphoneOnly(String filename) {
    try {/*from w  ww  .ja v  a  2 s .c om*/
        phonemaps = new HashMap<String, Integer>(400000);
        FileReader fileReader = new FileReader(filename);
        // Always wrap FileReader in BufferedReader.
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line;
        int count = 0;
        bufferedReader.readLine();
        while ((line = bufferedReader.readLine()) != null) {
            Scanner sc = new Scanner(line);
            sc.useDelimiter("\t");
            Integer id = sc.nextInt();
            String phone = sc.next();
            phonemaps.put(phone, id);
            count++;
            //                if(count%100==0){
            //                    System.out.println(count);
            //                }
        }
        bufferedReader.close();
    } catch (IOException ex) {
        Logger.getLogger(PhoneGraph.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.apache.sysml.api.mlcontext.MLContextUtil.java

/**
 * Compare two version strings (ie, "1.4.0" and "1.4.1").
 * //  ww  w .ja v  a  2 s.  co m
 * @param versionStr1
 *            First version string.
 * @param versionStr2
 *            Second version string.
 * @return If versionStr1 is less than versionStr2, return {@code -1}. If
 *         versionStr1 equals versionStr2, return {@code 0}. If versionStr1
 *         is greater than versionStr2, return {@code 1}.
 * @throws MLContextException
 *             if versionStr1 or versionStr2 is {@code null}
 */
private static int compareVersion(String versionStr1, String versionStr2) {
    if (versionStr1 == null) {
        throw new MLContextException("First version argument to compareVersion() is null");
    }
    if (versionStr2 == null) {
        throw new MLContextException("Second version argument to compareVersion() is null");
    }

    Scanner scanner1 = null;
    Scanner scanner2 = null;
    try {
        scanner1 = new Scanner(versionStr1);
        scanner2 = new Scanner(versionStr2);
        scanner1.useDelimiter("\\.");
        scanner2.useDelimiter("\\.");

        while (scanner1.hasNextInt() && scanner2.hasNextInt()) {
            int version1 = scanner1.nextInt();
            int version2 = scanner2.nextInt();
            if (version1 < version2) {
                return -1;
            } else if (version1 > version2) {
                return 1;
            }
        }

        return scanner1.hasNextInt() ? 1 : 0;
    } finally {
        scanner1.close();
        scanner2.close();
    }
}

From source file:org.kiji.bento.tools.MiniClusterTool.java

/**
 * Reads a pid from a file.//w  w w  .j a  va2  s  .  c  o m
 *
 * @return The pid extracted from the file.
 * @throws IOException If the file couldn't be read.
 */
private int readPidFile() throws IOException {
    int pid;
    Scanner scanner = new Scanner(mPidFile, "UTF-8");
    if (!scanner.hasNextInt()) {
        throw new IOException("Invalid pid file format.");
    }
    pid = scanner.nextInt();
    scanner.close();
    return pid;
}

From source file:com.planetmayo.debrief.satc.util.StraightLineCullingTestForm.java

private void loadFile(File file) throws IOException {
    Scanner scanner = new Scanner(file);
    scanner.useLocale(Locale.US);
    List<List<Coordinate>> coordinates = new ArrayList<List<Coordinate>>();
    while (true) {
        try {//from  w  w  w  . ja va2  s .  co m
            int num = scanner.nextInt();
            scanner.next();
            double x = scanner.nextDouble();
            double y = scanner.nextDouble();

            if (num > 0) {
                num--;
                while (coordinates.size() <= num) {
                    coordinates.add(new ArrayList<Coordinate>());
                }
                Coordinate coordinate = new Coordinate(x, y);
                coordinates.get(num).add(coordinate);
            }
        } catch (NoSuchElementException ex) {
            break;
        }
    }
    for (int i = 0; i < coordinates.size(); i++) {
        Coordinate c = coordinates.get(i).get(0);
        coordinates.get(i).add(c);
    }
    culling(coordinates);
}

From source file:br.edu.ifes.bd2dao.cgt.Menu.java

private Disciplina selecionarDisciplina() {
    System.out.println("Selecione uma das disciplinas abaixo: \n");
    listar(buscarDisciplinas());//from   w w  w .  j  ava 2 s .com
    System.out.println("Selecionar por:\n1 - ID\n2 - Nome e Perodo");
    Scanner opc = new Scanner(System.in);
    switch (opc.nextInt()) {
    case 1:
        return buscarDisciplinaPorId();
    case 2:
        return buscarDisciplinaPorNomeEPeriodo();
    default:
        return null;
    }
}

From source file:br.edu.ifes.bd2dao.cgt.Menu.java

private void deletarAluno() {
    System.out.println("Selecione um dos alunos abaixo: \n");
    listarAlunos();/*w w w.ja v a2  s  .  c  om*/
    System.out.println("Informe o id do aluno desejado: \n");
    Scanner alunoScan = new Scanner(System.in);
    int id = alunoScan.nextInt();
    new Aluno().deletar(new Long(id));
}

From source file:steamgameselector.SteamUtils.java

private void populateMap(Map map, String file) throws FileNotFoundException {
    map.clear();/*from w w  w  . j a v  a2  s. co  m*/
    Scanner sc = new Scanner(new File(file));
    while (sc.hasNextInt() && sc.hasNextLine()) {
        int id = sc.nextInt();
        sc.nextLine();
        if (sc.hasNextLine()) {
            map.put(id, sc.nextLine());
        }
    }
}

From source file:org.apache.hadoop.yarn.server.nodemanager.util.TestCgroupsLCEResourcesHandler.java

private int readIntFromFile(File targetFile) throws IOException {
    Scanner scanner = new Scanner(targetFile);
    try {//ww w  . j  a  v a  2 s.  c  o m
        return scanner.hasNextInt() ? scanner.nextInt() : -1;
    } finally {
        scanner.close();
    }
}

From source file:simcommunity.TheSim.java

public static void interactiveSim() {

    Scanner valore = new Scanner(System.in);
    /*int[] DNA;//from   w  ww  .  j a v  a  2 s  . co m
            
            
     Persona p = new Persona("Mario", 0, 9, 1024, 768);
            
     DNA = p.getDna();
            
     System.out.print("Stampo i dati di UNA persona");
     for (int i = 0; i < 9; i++) {
     System.out.print(DNA[i]);
     }
     System.out.println();*/

    System.out.print("\n===================================");
    System.out.print("\nCREAZIONE DELLA COMMUNITY");
    System.out.print("\n===================================");

    System.out.print("\n\nDimensione della comunit ");
    GlobalVar.dimensionecom = valore.nextInt();

    System.out.print("Numero collegamenti ");
    GlobalVar.numcollegamenti = valore.nextInt();

    System.out.print("Dimensione del DNA ");
    GlobalVar.dimDNA = valore.nextInt();

    System.out.print("Quante ere ");
    GlobalVar.numERE = valore.nextInt();

    System.out.print("Soglia di omogeneit ");
    GlobalVar.omoSoglia = valore.nextInt();

    //Community c = new Community(GlobalVar.dimensionecom, GlobalVar.numcollegamenti, GlobalVar.dimDNA, 1024, 768);
    Community c = new Community(GlobalVar.dimensionecom, GlobalVar.numcollegamenti, GlobalVar.dimDNA,
            GlobalVar.videoW, GlobalVar.videoH);
    ;
    Community cI = c;

    calcoloVicinato(c);

    disegnapallocco(cI, GlobalVar.vicinato, "Prima");
    Scanner sc = new Scanner(System.in);
    System.out.print("Premi invio per continuare. ");
    sc.nextLine();

    TraceCommunity(c);

    int era = 0;
    int idPersona;
    int idBit;
    //Omogeneit iniziale
    double omo = c.omogeneitacommunity();

    System.out.println("Omogeneit INIZIALE" + omo);

    //disegnare collegamenti TO DO
    while ((era < GlobalVar.numERE) && (omo < GlobalVar.omoSoglia)) {
        System.out.print("\nERA " + (era + 1));

        //prendo una persona a caso
        idPersona = (int) Math.floor(0 + (GlobalVar.dimensionecom) * Math.random());

        //prendo un bit a caso
        idBit = (int) Math.floor(0 + (GlobalVar.dimDNA) * Math.random());

        System.out.print("\nAggiorno la persona " + idPersona + " e il bit " + idBit);

        System.out.print("\nPrima");

        TraceDNA(c.getPersona(idPersona).getDna());

        c.cambia(idPersona, idBit);

        System.out.print("\nDopo");
        TraceDNA(c.getPersona(idPersona).getDna());

        omo = c.omogeneitacommunity();

        System.out.print("\n===================================");
        System.out.print("\nGrado di omogeneita': " + omo);
        System.out.print("\n===================================");

        era++;
    }

    calcoloVicinato(c);

    disegnapallocco(c, GlobalVar.vicinato, "Dopo");

}