复习代码
package cn.tedu.review;
public class ForDemo {
public static void main(String[] args) {
//需求1:向控制台打印9个!
for (int i = 0; i < 9; i++) {
System.out.print("!");
}
System.out.println();
//需求2:打印0-123 1-123 2-123
for (int i = 0; i < 3; i++) {
System.out.print(i);
for (int j = 1; j < 4; j++) {
System.out.print(j);
}
System.out.println();
}
//需求3:向控制台打印4*5的矩形
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
System.out.print("*");
}
System.out.println();
}
//需求4:向控制台打印6*6的左直角三角形
for (int i = 0; i < 6; i++) {
for (int j = 0; j <= i; j++) {
System.out.printf("*");
}
System.out.println();
}
}
}
continue 跳过当前循环执行,继续执行下一次循环
break 跳出循环
java数组
char类型的数组底层中做了处理,可以直接打印数组中的具体元素
但除了char类型以外的数组,如果想要查看数组中的具体元素,需要使用:
Arrays.toString(数组名),注意Arrays需要导包
copyOf的部分用法,数组的复制,缩容,扩容
package cn.tedu.Demo;
import java.util.Arrays;
public class TestCopyof {
public static void main(String[] args) {
//1.创建数组
int[] from = {1,2,3,4,5};
//2.1数组的普通复制
int[] to = Arrays.copyOf(from,5);
//2.2数组的扩容
int[] to2 = Arrays.copyOf(from,10);
System.out.println(Arrays.toString(to2));
//2.3数组的缩容
int[] to3 = Arrays.copyOf(from,3);
System.out.println(Arrays.toString(to3));
}
}



