* shuning uchun bu to'liq o'ziga xos misol. * @param ning mumkin bo'lgan URL manzili private static boolean isValidURL(@Nonnull final String s) { try { new URL(s); return true; } catch (final MalformedURLException e) { return false; } } private static void output(@Nonnull final String format, @Nonnull final Object... args) { System.out.println(format(format, args)); } public static void main(final String[] args) { final Scanner sis = new Scanner(System.in); - output(HELP_MESSAGE);
- while (sis.hasNext()){
- if (sis.hasNextInt()){
- final int next = sis.nextInt();
- output("You entered an Integer = %d", next);
- }
- else if (sis.hasNextLong())
- {
- final long next = sis.nextLong();
- output("You entered a Long = %d", next);
- }
- else if (sis.hasNextDouble())
- {
- final double next = sis.nextDouble();
- output("You entered a Double = %f", next);
- }
- else if (sis.hasNext("\\d+"))
- {
- final BigInteger next = sis.nextBigInteger();
- output("You entered a BigInteger = %s", next);
- }
else if (sis.hasNextBoolean())
{
final boolean next = sis.nextBoolean();
output("You entered a Boolean representation = %s", next);
}
else if (sis.hasNext(DATE_PATTERN))
{
final String next = sis.next(DATE_PATTERN);
output("You entered a Date representation = %s", next);
}
Do'stlaringiz bilan baham: |