Programming Questions for final examsreturn
This is a programming question for the final exam, and in 60 minutes you can submit it several times until it is correct.
Warm tips:
1. This exam belongs to the online Judge topic and is enigmatic grading by the system immediately after submission.
2. Students can submit their answers before the test deadline and the system will take the highest score as the final result.
12 the leading 0 (10 points) of the binary
Topic content:
The computer internally uses binary to express all values. A decimal number, such as 18, is expressed as 00000000000000000000000000011000 inside a 32-bit computer. As you can see, count from the left, before the first 1, there are 27 0. We call these 0 the leading 0.
Now, your task is to write a program, enter an integer, and output the number of its leading 0 in 32-bit binary representations.
Input format:
An integer that can be expressed within the range of 32-bit integers.
Output format:
An integer that expresses the number of 0 that the input is expressed as a 32-bit binary number, before the first 1.
Input Sample:
256
Sample output:
23
time limit: 500ms memory limit: 32000kb
Import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner sc = new Scanner (system.in); T number = 0;//An integer that can be expressed within the range of 32-bit integers. int wei = 32;//32-bit computer string result = null;//string number = Sc.nextint ();//Input result = integer.tobinarystring (number);//Re Turns a string representation of the integer argument as an unsigned integer in base 2.if (number! = 0) {//an integer, the expression input is expressed as a A 32-bit binary number, the number of 0 before the first 1. System.out.println (Wei-result.length ());} else {System.out.println (wei);}}}
China MOOC_ 0 Fundamentals Java Language _ Final exam programming _1 binary Preamble 0