use of java.util.InputMismatchException in project Homework by KST-Scale.
the class Homework1 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;
}
use of java.util.InputMismatchException in project Homework by KST-Scale.
the class Work2 method readNextInt.
private int readNextInt() {
int selection = -1;
System.out.print(INPUT_TEXT);
Scanner scanner = new Scanner(System.in);
try {
selection = scanner.nextInt();
} catch (InputMismatchException e) {
System.out.println(ERROR_INVALID_INPUT_MSG);
return selection;
}
return selection;
}
use of java.util.InputMismatchException in project Java by TheAlgorithms.
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));
}
use of java.util.InputMismatchException in project competitive-programming by ttvi-cse.
the class FlipCoinInputReader 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;
}
use of java.util.InputMismatchException in project competitive-programming by ttvi-cse.
the class DiscrepanciesInVL 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;
}
Aggregations