Java language Basics Related issues

Source: Internet
Author: User

Sometimes I think I do nothing, write the program can not do, and then the simple operation will also have problems and so on. Through the "Boulevard to Jane" Reading and the teacher's explanation I know that is a lack of self-confidence, is the so-called "book Mountain has no Royal road as the path, the knowledge of the endless bitter boat", in the program should find the right way to learn the classification and analysis of problems. Should learn their own records summary, each installation should have a detailed summary, in a variety of environments to try their own installation, there are problems, should first resolve, if you ask others, you need to record the steps to solve. Programming should master four programming steps: The first describes the design ideas in natural language before writing the code. The second part draws the program flowchart according to the design idea. The third write pseudo-code, use the half program language and the natural language mixed description way, writes solves the process. Finally, after the completion of programming debugging, the collection of small sets of large.

* Action Brain 1:

Question 1: Read the example carefully : Enumtest.java, run it, analyze the running results?

Source:

public class Enumtest {

public static void Main (string[] args) {

Size S=size.small;

Size T=size.large;

S and T refer to the same object?

System.out.println (s==t);

is the original data type? is not

System.out.println (S.getclass (). isprimitive ());

Convert from String

Size u=size.valueof ("SMALL");

System.out.println (S==u); True

list all of its values

For (Size value:Size.values ()) {

System.out.println (value);

}

}

}

Enum Size{small,medium,large};

Run results

False

False

True

SMALL

MEDIUM

LARGE

Question two: What conclusions can you get? Have you mastered the basic usage of enum types?

Constants of enumerated types are stored in the form of strings. In source codesand theTis not the original data type. getclass ():gets the current object that owns theClassobject;ISprimitive: Used to determine the specifiedClassclass is a basic type;S.getclass (). Isprimitive () is used to determineswhether it is a basic type. Size u=size.valueof ("SMALL"), which is used to convert the data type.Size.value ()can traverseSizeall the elements in the. Use the=="andequals ()method directly compared to the value of the enumeration variable.

* hands-on brain 2

Why is the numeric value of a double type not "mathematically accurate" result?

Float and double types are primarily designed for scientific calculations and engineering calculations, and they perform binary floating-point operations, which are divided into three parts: The sign bit, the exponent, and the tail part of the computer. When data is stored as binary in the computer, a series of wireless loops appears, and errors occur during data conversion. Decimal is not an accurate representation of 1/3, and the same binary does not accurately represent 1/10.

* hands-on brain 3

What is the output of the following code?

int x=100;

int y=200;

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

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

Output result:x+y=100200 300=x+y

Why is there such an output result?

Statement one output in the "+" connection literal, the result is that X and Y will connect the two data.

The "+" in the two outputs of the statementis an operator that sums X and Y .

* after-school exercises:

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 Java The number in the above is expressed by which code.

The original code: the original code is the absolute value of the symbol bit plus the truth , that is, the first digit symbol , the remaining bits represent values .

Inverse code: Positive number: The inverse code of positive number is the same as the original code. Negative number: The inverse of the negative, the sign bit is "1", the numeric part is reversed by a bit. It can be seen that if an inverse code represents a negative number , the human brain cannot visually see its value . it is usually converted to the original code and then calculated .

Complement: A positive complement is its own. The complement of a negative number is on the basis of its original code , The sign bit is unchanged , the rest of you take the counter, the last +1. ( that is, on the basis of the inverse code + 1). For negative numbers , the complement representation is also the human brain can not intuitively see its value . It is also often necessary to convert the original code to calculate its value .

* after-school assignments 1

1, write a program, the user input two number, to find out its subtraction, and the message box display calculation results.

Source:

Import Java.util.Scanner;

Import javax.swing.joptionpane;//Import Class Joptionpane

public class Operation {

public static void Main (String args[]) {

Scanner input=new Scanner (system.in);

System.out.println (" Please enter two integers:");

Double A, B;

A=input.nextdouble (); Enter first number

B=input.nextdouble (); Enter a second number

Double sum,difference,product,quotient;

Sum=a+b;

Difference=a-b;

Product=a*b;

quotient=a/b;

Output dialog box displays the results

Joptionpane.showmessagedialog (

NULL, "The sum is" + sum + "\ n" +

"The difference is" + difference + "\ n" +

"The product is" +product+ "\ n" +

"The quotient is" +quotient, "Results",

Joptionpane.plain_message);

System.exit (0);

}

}

Operation Result:

Java language Basics Related issues

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.