Advertisement
LisunovaMaryna

правка

Oct 4th, 2023 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.11 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main
  3. {
  4.     public static void main(String[]args)
  5.     {
  6.         int numM;
  7.         int numK;
  8.         int num;
  9.         boolean isCorrect;
  10.         numM = 0;
  11.         num = 4;
  12.         numK = 0;
  13.         Scanner scan = new Scanner(System.in);
  14.         System.out.print("Given an integer m > 10. Find the largest integer k for which 4^k < m.\n");
  15.         System.out.print("Enter an integer (>10): ");
  16.         do
  17.         {
  18.             isCorrect = true;
  19.             try {
  20.                 numM = Integer.parseInt(scan.next());
  21.             }
  22.             catch (NumberFormatException e) {
  23.                 System.out.print("Incorrect value. Enter the number: ");
  24.                 isCorrect = false;
  25.             }
  26.             if ((!isCorrect) && (numM < 10))
  27.             {
  28.                 System.out.print("Incorrect value. Enter the number: ");
  29.                 isCorrect = false;
  30.             }
  31.         } while (isCorrect);
  32.         scan.close();
  33.         while (num < numM) {
  34.             num = num * 4;
  35.             numK++;
  36.         }
  37.         System.out.print(numK);
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement