Search in sources :

Example 76 with InputMismatchException

use of java.util.InputMismatchException in project MyAlg by tyuan73.

the class IOUtils method readInt.

public int readInt() {
    int c = read();
    while (isSpaceChar(c)) c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    int res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
}
Also used : InputMismatchException(java.util.InputMismatchException)

Example 77 with InputMismatchException

use of java.util.InputMismatchException in project MyAlg by tyuan73.

the class InputReader method readInt.

public int readInt() {
    int c = read();
    while (isSpaceChar(c)) c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    int res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
}
Also used : InputMismatchException(java.util.InputMismatchException)

Example 78 with InputMismatchException

use of java.util.InputMismatchException in project MyAlg by tyuan73.

the class InputReader method readLong.

public long readLong() {
    int c = read();
    while (isSpaceChar(c)) c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    long res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
}
Also used : InputMismatchException(java.util.InputMismatchException)

Example 79 with InputMismatchException

use of java.util.InputMismatchException in project MyAlg by tyuan73.

the class OutputWriter method readLong.

public long readLong() {
    int c = read();
    while (isSpaceChar(c)) c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    long res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
}
Also used : InputMismatchException(java.util.InputMismatchException)

Example 80 with InputMismatchException

use of java.util.InputMismatchException in project KursJava by SamouczekProgramisty.

the class Exercise method main.

public static void main(String[] args) {
    System.out.println("Podaj liczbę: ");
    Scanner input = new Scanner(System.in);
    double userInput = 0;
    while (true) {
        try {
            userInput = input.nextDouble();
            break;
        } catch (InputMismatchException e) {
            System.out.println("Podaj poprawną liczbę!");
            // ignoring wrong token
            input.next();
        }
    }
    if (userInput < 0) {
        throw new IllegalArgumentException(String.format("Pierwiastek kwadratowy z liczby rzeczywistej %.4f nie istnieje!", userInput));
    }
    System.out.print(String.format("Pierwieastek z %.4f to %.4f.", userInput, Math.sqrt(userInput)));
}
Also used : Scanner(java.util.Scanner) InputMismatchException(java.util.InputMismatchException)

Aggregations

InputMismatchException (java.util.InputMismatchException)83 Scanner (java.util.Scanner)56 NoSuchElementException (java.util.NoSuchElementException)47 Locale (java.util.Locale)23 BufferUnderflowException (java.nio.BufferUnderflowException)5 Pattern (java.util.regex.Pattern)5 BufferedReader (java.io.BufferedReader)4 BigInteger (java.math.BigInteger)4 UnicodeReader (gdsc.core.utils.UnicodeReader)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)2 TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)2 Point (java.awt.Point)2 Serializable (java.io.Serializable)2 BigDecimal (java.math.BigDecimal)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1