General Pattern bu eng keng tarqalgan vazifalar haqida so'radi - Quyida System.in dan foydalanuvchi ma'lumotlarini interaktiv tarzda o'qish uchun java.util.Scanner sinfidan qanday qilib to'g'ri foydalanish kerakligi ko'rsatilgan.
- to'g'ri (ba'zan stdin deb ataladi, ayniqsa C, C ++ va boshqa tillarda, shuningdek Unix va Linuxda). Bu
- qilish so'raladigan eng keng tarqalgan narsalarni idiomatik tarzda namoyish etadi.
-
- package com.stackoverflow.scanner;
- import javax.annotation.Nonnull;
- import java.math.BigInteger;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.*;
- import java.util.regex.Pattern;
- import static java.lang.String.format;
- public class ScannerExample
- {
- private static final Set EXIT_COMMANDS;
- private static final Set HELP_COMMANDS;
- private static final Pattern DATE_PATTERN;
- private static final String HELP_MESSAGE;
- static
- {
final SortedSet ecmds = new TreeSet(String.CASE_INSENSITIVE_ORDER);
ecmds.addAll(Arrays.asList("exit", "done", "quit", "end", "fino"));
EXIT_COMMANDS = Collections.unmodifiableSortedSet(ecmds);
final SortedSet hcmds = new TreeSet(String.CASE_INSENSITIVE_ORDER);
hcmds.addAll(Arrays.asList("help", "helpi", "?"));
HELP_COMMANDS = Collections.unmodifiableSet(hcmds);
DATE_PATTERN = Pattern.compile("\\d{4}([-\\/])\\d{2}\\1\\d{2}"); //
http://regex101.com/r/xB8dR3/1
HELP_MESSAGE = format("Please enter some data or enter one of the following commands to
exit %s", EXIT_COMMANDS);
}
*Bajarish oqimini boshqarish uchun istisnolardan foydalanish har doim yomon.
Do'stlaringiz bilan baham: |