Advertisement
LisunovaMaryna

lab1.3 java

Sep 30th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 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, NumK, Num;
  7.         boolean IsCorrect;
  8.         NumM = 0;
  9.         Num = 4;
  10.         NumK = 0;
  11.         Scanner in = new Scanner(System.in);
  12.         System.out.print("Given an integer m > 10. Find the largest integer k for
  13.                          which 4^k < m.\n");
  14.         System.out.print("Enter an integer (>10): ");
  15.         do
  16.         {
  17.             IsCorrect = false;
  18.             try {
  19.                 NumM = Integer.parseInt(in.next());
  20.             }
  21.             catch (NumberFormatException e) {
  22.                 System.out.print("Incorrect value. Enter the number: ");
  23.                 IsCorrect = true;
  24.             }
  25.             if ((!IsCorrect) && (NumM < 10))
  26.             {
  27.                 System.out.print("Incorrect value. Enter the number: ");
  28.                 IsCorrect = true;
  29.             }
  30.         } while (IsCorrect);
  31.         in.close();
  32.         while (Num < NumM) {
  33.             Num = Num * 4;
  34.             NumK++;
  35.         }
  36.         System.out.print(NumK);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement