Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the control flow, large value and array in the consolidation of Java core technology

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to understand control flow and large values and arrays in the consolidation of Java core technology". In daily operation, it is believed that many people have doubts about how to understand control flow and large values and arrays in the consolidation of Java core technology. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the doubts of "how to understand control flow and large values and arrays in the consolidation of Java core technology"! Next, please follow the editor to study!

Catalogue

1. Control flow

1.1 block scope

1.2 conditional statement

two。 Large number

3. Array

3.1 Command line arguments

1. Control flow 1.1 block scope

[error prone points]: variables with the same name cannot be declared in two nested blocks, such as

Public static void main (String [] args) {int n;... {int n; / / Error--can't redefine n in inner block}}

The code cannot be compiled because a variable with the same name appears in two nested blocks

Note:

In C++, you can redefine a variable in a nested block. Variables defined in the inner layer override those defined in the outer layer.

1.2 conditional statement

[error prone points]: in a loop, checking whether two floating point numbers are equal requires special attention, such as

For (double x = 0; x = 10; x = 0.1)

The above loop will not end, because 0.1 cannot be accurately expressed in binary, so x will jump from 9.99999999999998 to 10.09999999999998.

[supplement]: if the case branch statement in the switch statement does not add break at the end, it is actually a more dangerous situation. So you can write the javac-Xlint:fallthrough file name .java when you compile the code with the switch statement. If someone in a branch is missing break, the compiler will warn you. If you just need some branches that are not followed by break, you can add a @ SuppressWarnings ("fallthrough") to their peripheral methods so that no warnings are generated for the methods.

[supplement]: Java does not have a goto statement, but break can be tagged, which can be used to jump out of the inner loop. Such as

Int n read data while () {for () {... Break read_data;...}}

Note:

In this way, you can only jump out of the statement block, not into the statement block.

two。 Large number

[supplement]: if the basic integers and floating point numbers do not meet the requirements, you can use the two classes in the java.math package: BigInteger and BigDecinmal. These two classes can handle numeric values that contain sequences of numbers of any length. BigInteger class implements arbitrary precision integer operation, and BigDecinmal implements arbitrary precision floating point number operation.

3. Array

[error prone points]: the array length in Java does not need to be constant. For example, new int [n] creates an array of length n. But after determining the value of n, it cannot be changed.

3.1 Command line arguments

[supplement]: every Java application has a main method with a String [] args parameter. This parameter indicates that the main method will accept an array of strings, that is, command-line arguments. Such as

Public class Message {public static void main (String [] args) {if (args.length==0 | | args [0] .equals ("- h")) {System.out.print ("Hello,");} else if (args [0] .equlas ("- g")) {System.out.print ("Goodbye,");} for (int iTunes

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report