Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main
- {
- public static void main(String[]args)
- {
- int numM;
- int numK;
- int num;
- boolean isCorrect;
- numM = 0;
- num = 4;
- numK = 0;
- Scanner scan = new Scanner(System.in);
- System.out.print("Given an integer m > 10. Find the largest integer k for which 4^k < m.\n");
- System.out.print("Enter an integer (>10): ");
- do
- {
- isCorrect = true;
- try {
- numM = Integer.parseInt(scan.next());
- }
- catch (NumberFormatException e) {
- System.out.print("Incorrect value. Enter the number: ");
- isCorrect = false;
- }
- if ((!isCorrect) && (numM < 10))
- {
- System.out.print("Incorrect value. Enter the number: ");
- isCorrect = false;
- }
- } while (isCorrect);
- scan.close();
- while (num < numM) {
- num = num * 4;
- numK++;
- }
- System.out.print(numK);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement