Q:

Write a Java program that returns the largest integer but not larger than the base-2 logarithm of a specified integer

0

Write a Java program that returns the largest integer but not larger than the base-2 logarithm of a specified integer

Original Number: 2350
Result: 115

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class Solution {
	     
    public static void main(String[] args) {
        int n = 2350;
		System.out.printf("Original Number: %d\n", n);
		int shift_right_count = 0;
        do {
            n >>= 1;
            shift_right_count++;
        } while (n != 0);
         shift_right_count--;
        System.out.printf("Result: %s\r\n", shift_right_count);
    }
}

Sample Output:

Original Number: 2350
Result: 11

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now