One-dimensional arrays:Int[] a={1,2,3};for (int i:a) {System.out.print (i+ "");}Output: 1 2 3Two-dimensional arrays:Import Java.util.scanner;public class Tet {public static void main (string[] args) {//int[][] b={{1,2,3},{4,5,6}}; line int[][ ] A=new int[5][];//must specify the number of rows for (int i=0;iOutput:0 0 00 0 00 0 00 0 00 0 0The use of enhanced for loops in one-dimensional and two-dimensional arrays in
expression.Parameter regex is a regular-expression matching pattern instead of a simple string, and he may have unexpected results for some special characters, such as testing the following code with a vertical bar | Delimited string, you will not get the expected resultFor example the situation A:AAA|BBB|CCC string[] aa = "AAA|BBB|CCC". Split ("\\|" ); This will get the correct result for (int i = 0; I ) { System.out.println ("--" +
7>aa[i]);
such as B:AAA*BBB*CCC
Learn to program Java learning nested loop released, welcome to visit through Xuebiancheng8.comThe Java nested loops are mainly referred to in while,do...while, and for loops can be nested in each other, for example, in the while loop can nest Do...while loops, in Do...while
Learn to program Java learning nested loop released, welcome to visit through Xuebiancheng8.comThe Java nested loops are mainly referred to in while,do...while, and for loops can be nested in each other, for example, in the while loop can nest Do...while loops, in Do...while
1 in Java, to jump out of multiple loops, you can define a label in front of the outer loop statement, and then in the code of the Inner loop bodyUse the break statement with a label to jump out of the outer loop. For exampleOk:for (int i=0;i{for (int j=0;j{System.out.println ("i=" + i + ", j=" + j);if (J ==5) break OK;}}2 Let the result of the outer loop condition expression be subject to the inner loop bo
Java is a strongly typed language, and Python is a weakly typed language.First look at the for loop used in Java, such as:package test06;/* * for 循环的条件 * for (循环初始表达式;循环条件表达式;循环后的表达式) */public class Fortest { public static void main(String[] args){ /*打印九九乘法表*/ for(int x=1;xResults such as:And look at the use of the For loop in Python:for x in range(1,10): for y in range(1,x+1): if
one, the marking wayIn Java, to jump out of multiple loops, you can define a label before the loop statement outside, and then use the label break statement in the code of the inner loop body to jump out of the outer loop. For example:
OK:
for (int i=0;i
second, break out of the current cycle, through the internal jump out of the condition control outside the loop
for (int i=0;i
three, throw the exception
function: Add (add) or subtract (sub) A time interval value (expr) for a given time date, respectivelyFormat: (1) interval is the key word for time interval(2) expr is an expression that corresponds to the following type(3) unit is the interval of units (interval type) (20), as follows: Example 1: (the current time plus one day) Example 2: (Minus one minute a day) 4. Personalized Display Date: (1) DayOfWeek (date); --The day of the week (2) DayOfMonth (data); --The day of the first one (
);//output The value of an array element individually the } + } - } the Bayi /** the * foreach output three-dimensional array the */ - Public voidtestArray3 () { - intArr[][][] = { the{{1, 2}, {3, 4}}, the{{5, 6}, {7, 8}} the }; the -SYSTEM.OUT.PRINTLN ("----4----foreach output three-dimensional array test"); the for(int[] a2:arr) { the for(int[] a1:a2) { the for(in
, that's the difference between running time. The i++ statement in Java requires a temporary variable to fetch the value before the increment, and ++i does not need it. This causes the system to request a memory space first when using i++, then plug the value into it, and then release it at last. This is a series of operating time.We can chew on the beginning of this sentence: ++i is the first to execute i = i +1 and then use the value of I, and i++ i
defining a method, you do not know that you can use a variable parameter when you define several parameters - * 2. Format: the * Modifier return value type method name (data type ... Variable name)Bayi * the * 3. Precautions: the * This mutable parameter is essentially an array - * If there are multiple parameters, the variable parameter must be placed in the last - */ the Public Static voidMain (string[] args) { the the int[] arr = {11, 22, 33, 44}; the //p
Based on the new features of JDK5, use a for loop map, such as the Key for loop map
123
for(String dataKey : paraMap.keySet()) {System.out.println(dataKey );}
Note how paramap is defined, if it is a simple map paramap = new HashMap (); The string in front can only be converted to object.The key and value of the entire map
123456789101112
Mapnew LinkedHashMapmap.put(1,"星期一");map.put(2,"星期二");map.put(3,"星期三");map.put(4,"星期四");map.put(5,"星期五");map.pu
In Java, exiting multiple loops lets you exit by using the control of the outer loop to receive the inner loop control. Here use the label to exit the loop. Here's a demo:
public class Test
{public
static void Main (string[] args)
{
int array[][] = {1, 2, 5,},{4, 5, 6},{3 , 2, 5}};
mark:for (int i = 0; i
The following are the output results:1I am the outer loop!2I am the outer loop!5Found Number 5!
Java tutorial translation Sequence Java Introduction Build a JSE development environment-install JDK and eclipse Language basics Java Hello World Program Analysis Variable Java Variables Java Native type Conversion of
Preach Wisdom Blog Video tutorial Download summary |java video tutorial |net video tutorial |php video tutorial | Web video Tutorial
Preach Wisdom Blog Video tutorial Download summary
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.