package Day5;
public class Num31 {
public static void main(String[] args) {
int[][] a=new int[4][];
a[0]=new int[5];
a[1]=new int[3];
a[2]=new int[6];
a[2][2]=2;
int[][] b=new int[3][4];
b[1][3]=5;
for(int i=0;i<b.length;i++){
for(int j=0;j<b[i].length;j++){
b[i][j]=5;
System.out.println(b[i][j]);
}
}
}
}
```java
package Day5;
import java.util.Arrays;
public class Num3 {
public static void main(String[] args) {
int[] a={1,2,13,14,15,16,14};
a=Arrays.copyOf(a,a.length+2);
a[a.length-2]=100;
a[a.length-1]=200;
System.out.println(Arrays.toString(a));
int[] b=new int[a.length+3];
System.arraycopy(a,0,b,0,3);
b[b.length-3]=100;
b[b.length-2]=200;
b[b.length-1]=300;
System.out.println(Arrays.toString(b));
}
}
public class Num2 {
public static void main(String[] args) {
int[] a = {2, 5, 8, 9, 6};
int[] b = new int[a.length + 1];
b[b.length - 1] = 8;
System.arraycopy(a, 0, b, 0, 5);
System.out.println(Arrays.toString(a));
a = Arrays.copyOf(a, a.length + 1);
a[a.length - 1] = 9;
System.out.println(Arrays.toString(a));
}
}
```java
String字符串:
构造方法:
String s = "hello";
String()
String(String)
String(char[])
String(char[], int offset, int count)
String(byte[])
String(byte[], int offset, int length)
public class Num02 {
public static void main(String[] args) {
//1.简单写法
String s="hello";
//2.无参构造器--->""空的字符串
String s1=new String();
//3.有参构造器1
String s2=new String("hello");
//4.有参构造器2
char[] chs={'h','e','l','l','o'};
String s3=new String(chs);
//5.有参构造器3 输出ello
String s4=new String(chs,1,4);
//6.有参构造器4 输出ABCDa //byte可以转换成char类型
byte[] bs={65,66,67,97};//或byte[] bs={65,66,67,97};
String s5=new String(bs);
//7.有参构造5 输出ABC
String s6=new String(bs,0,3);
System.out.println(s5);
}
}