China MOOC_ 0 Fundamentals Java Language _ Final exam programming _1 binary Preamble 0

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.