1 public class Demo03 { 2 static char ch[] = {‘1‘,‘2‘,‘3‘,‘4‘}; 3 static char ch01[] = new char[ch.length-1]; 4 public static void main(String[] args) { 5 newch(2); 6 } 7 public static void newch(int i){ 8 if(i==0){ 9 for(int a=0;a<ch.length-1;a++) 10 ch01[a] = ch[a+1]; 11 } 12 if(0<i & i<ch.length-1){ //ch.length = 4 13 for(int a=0;a<i;a++){ 14 ch01[a] = ch[a]; //a = 0--(i-1) 15 } 16 for(int b=i;b<ch.length-1;b++){ 17 ch01[b] = ch[b+1]; 18 } 19 } 20 for(int c=0;c<ch01.length;c++){ 21 System.out.println(ch01[c]); 22 } 23 } 24 }
输出结果为:
1
2
4
时间: 2024-10-08 06:50:08