public static void main(String[] args) {
int[] a = {1,3,7,15,20,30,45,89};
int c = 29;
int i =0;
int[] a1 = new int[a.length+1];
for (i = 0; i < a.length; i++) {
if(i<a.length-1&&a[i]>c){
for (int j = 0; j < a1.length; j++) {
if(j<i){
a1[j]=a[j];
}else if(j==i){
a1[j]=c;
}else{
a1[j]=a[j-1];
}
}
}
if (a[a.length-1]<c){
for (int j = 0; j < a1.length; j++) {
if(j<a1.length-1){
a1[j]=a[j]
}else{
a1[j]=c;
}
}
}
}
}
} |