Java Basics Review -2 (Boolean short-circuit problem, operator precedence and reference data type)

Source: Internet
Author: User

1 short circuit with &&, when the left is false, do not execute to the right;

Short Circuit or | |, when its left is true, does not execute to the right.

2 int a=1;

if (a++==2) {

A = 7;

}

System.out.println (a);

The output is 2, because when + + is on the right side of a, the first to determine whether a is equal to 2, and then add 1, when + + on the left of a, the first to add 1, and then determine whether equal to 2

3 referencing the scanner data type format:

First in the class outside the Guide package import Java.util.Scanner;

Then create the new object in the class with the data type Scanner sc = new Scanner (system.in);

again to invoke the functionality in the object int i = Sc.nextint ();//used to receive console input numbers

                                 string s = Sc.next ();//A string used to receive console input

4 referencing the random data type format

First in the class outside the Guide package import java.util.Random;

Then create the data type new object in the class                                   Random rd = new random (), and then invoke features in the object                                                 

again to invoke the functionality in the object int i = Rd.nextint (10);//random integer used to receive "0,10"

                                 Double s = rd.nextdouble ();//random decimals used to receive "0.0,1.0"

Java Basics Review -2 (Boolean short-circuit problem, operator precedence, and reference data type)

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.