比如说数组1 2 3 4 5
变成 2 3 4 5
#include<stdio.h>
int main()
{
int t[5]= {1,2,3,4,5};
int j;
for(j=0; j<5-1; j++)
{
t[j]=t[j+1];
}
for(j=0; j<5-1; j++)
{
printf("%d ",t[j]);
}
return 0;
}
这个是Java实现的删除1的代码,如果需要其他的,或者其他要求,可以继续提问,感谢采纳!
public class Test {
public static void main(String[] args) {
int[] arr = new int[]{1,2,3,4,5};
int[] arr_new = new int[arr.length-1];
int j=1;
for(int i=0, k=0;i<arr.length;i++){
if(i!=j-1){
arr_new[k]=arr[i];
k++;
}
}
System.out.println("Before deletion :" + Arrays.toString(arr));
System.out.println("After deletion :" + Arrays.toString(arr_new));
}
}