Search in sources :

Example 21 with InputMismatchException

use of java.util.InputMismatchException in project j2objc by google.

the class InputMismatchExceptionTest method test_Constructor.

/**
     * @tests java.util.InputMismatchException#InputMismatchException()
     */
@SuppressWarnings("cast")
public void test_Constructor() {
    InputMismatchException exception = new InputMismatchException();
    assertNotNull(exception);
    assertTrue(exception instanceof NoSuchElementException);
    assertTrue(exception instanceof Serializable);
}
Also used : Serializable(java.io.Serializable) InputMismatchException(java.util.InputMismatchException) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with InputMismatchException

use of java.util.InputMismatchException in project BaseProject by fly803.

the class AnyBaseToAnyBase method main.

// Driver
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String n;
    int b1 = 0, b2 = 0;
    while (true) {
        try {
            System.out.print("Enter number: ");
            n = in.next();
            System.out.print("Enter beginning base (between " + MINIMUM_BASE + " and " + MAXIMUM_BASE + "): ");
            b1 = in.nextInt();
            if (b1 > MAXIMUM_BASE || b1 < MINIMUM_BASE) {
                System.out.println("Invalid base!");
                continue;
            }
            if (!validForBase(n, b1)) {
                System.out.println("The number is invalid for this base!");
                continue;
            }
            System.out.print("Enter end base (between " + MINIMUM_BASE + " and " + MAXIMUM_BASE + "): ");
            b2 = in.nextInt();
            if (b2 > MAXIMUM_BASE || b2 < MINIMUM_BASE) {
                System.out.println("Invalid base!");
                continue;
            }
            break;
        } catch (InputMismatchException e) {
            System.out.println("Invalid input.");
            in.next();
        }
    }
    System.out.println(base2base(n, b1, b2));
}
Also used : Scanner(java.util.Scanner) InputMismatchException(java.util.InputMismatchException)

Example 23 with InputMismatchException

use of java.util.InputMismatchException in project Homework by KST-Scale.

the class Homework3 method readNextInt.

private static Integer readNextInt() {
    Integer input = null;
    System.out.print(INPUT_TEXT);
    Scanner scanner = new Scanner(System.in);
    try {
        input = scanner.nextInt();
    } catch (InputMismatchException e) {
        System.out.println(ERROR_INVALID_INPUT_MSG);
        return input;
    }
    return input;
}
Also used : Scanner(java.util.Scanner) InputMismatchException(java.util.InputMismatchException)

Example 24 with InputMismatchException

use of java.util.InputMismatchException in project Homework by KST-Scale.

the class Homework5 method readNextInt.

private static Integer readNextInt() {
    Integer input = null;
    System.out.print(INPUT_TEXT);
    Scanner scanner = new Scanner(System.in);
    try {
        input = scanner.nextInt();
    } catch (InputMismatchException e) {
        System.out.println(ERROR_INVALID_INPUT_MSG);
        return input;
    }
    return input;
}
Also used : Scanner(java.util.Scanner) InputMismatchException(java.util.InputMismatchException)

Example 25 with InputMismatchException

use of java.util.InputMismatchException in project Kattis by MiKoMW.

the class IntSortedArray 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)

Aggregations

InputMismatchException (java.util.InputMismatchException)82 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