Java Classroom Small Homework

Source: Internet
Author: User

Thinking about the problems of 1.java enumeration type and data binary system

What is the output of the following code? Why is there such an output result?

int x=100;

int y=200;

System.out.println ("x+y=" +x+y);

System.out.println (x+y+ "=x+y");

answer: The result of the output is X+y=100 300=x+y; The first +x+y means to add "X", "Y" two variables after the "x+y=" string, and the second x+y is the variable x and Y to add

2. Read the example carefully : Enumtest.java, run it, analyze the running results? What conclusions can you get? Have you mastered the basic usage of enum types?

A: The conclusion is that the enum type is a reference type! An enumeration is not part of the original data type, and each of its specific values refers to a specific object. The same value refers to the same object.

You can use the "= =" and the Equals () methods to directly compare the values of the enumeration variables, in other words, the result of the "= =" and the Equals () methods are equivalent for variables of enum types.

3. read the corresponding textbook, or use the Internet search engine, find out the anti-code, complement and the original code of the concepts, and then write a sample program, the positive numbers, negative numbers of various bit operations, observe the output, and the results of the manual calculation, to see the number in Java is the above-mentioned code representation.

Answer: 1. The original code is the absolute value of the symbol bit plus the truth, that is, the first digit to represent the symbol, the remaining bits represent the values. 2. The inverse code is represented by: positive inverse code is its own negative number of the inverse code is in its original code base, the sign bit is unchanged, the rest of the bits are reversed. 3. The complement is the complement of the positive is its own, the complement of the negative is in its original code , the sign bit unchanged, the rest of you take the counter, +1. (That is, on the basis of the anti-code +1). The complement is used in Java.

4. Please run the following code (TESTDOUBLE.JAVA)

5. Why is the numeric value of a double type not "mathematically accurate"? Please find information through the Internet, or read the relevant computer textbooks to solve this problem. (Hint: This problem is related to how floating-point numbers are represented inside a computer)

A: This involves a binary and decimal conversion problem. A value of type double takes 64bit, or 64 binary numbers, except that the highest bit represents the positive and negative sign, and the lowest bit is bound to have an error with the actual data (unless the actual data is exactly 2 of the n-th square).

6.Java variable follows the shield principle of variable with the same name

The output result is 2;

Java Classroom Small Homework

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.