Guruh talabasi Qurbonov Tohirjonning Dasturlash1 fanidan taqdimoti


* Shuning uchun bu usulda inkapsullangan, bu shunday qilingan


Download 98.42 Kb.
bet4/8
Sana18.06.2023
Hajmi98.42 Kb.
#1571789
1   2   3   4   5   6   7   8
Bog'liq
650-22guruh talabasi Qurbonov Tohirjonning Dasturlash1 fanidan taqdimoti

* Shuning uchun bu usulda inkapsullangan, bu shunday qilingan

* har qanday tashqi kutubxonalarni kiritmaslik uchun maxsus usul

* shuning uchun bu to'liq o'ziga xos misol.

* @param ning mumkin bo'lgan URL manzili

* @return true, agar s haqiqiy urlni bildirsa, aks holda false

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);
}

Download 98.42 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling