My method which contains no java collections
public class Main {
public static void main(String[] args) {
/** By Boris Elkin 21.09.2018 в 22.59 MSK You can input any digits, sorting was made without collections on purpose.
**/
int[] a1=new int[]{1,245623,3,3,3,3454,6,8123,234,123123,797897};
int[] a2=new int[]{234234, 33,4234,5,646456,9,78};
int[] a3;
a3= collide(a1, a2);
a3=sort(a3);
checkArray(a3);
}
public static int[] collide(int[]a, int[]b){
int breakpoint=0;
int size=a.length+b.length;
int[]c=new int[size];
for(int i=0;i<a.length;i++){
c[i]=a[i];
breakpoint=i;
}
for(int i=breakpoint+1,j=0;j<b.length;i++, j++){
c[i]=b[j];
}
return c;
}
public static int[] sort(int a[]){
boolean engine=true;
while(engine) {
for(int i=0;i<a.length;i++){
int temp, temp2;
if ((i + 1 < a.length) && (a[i] > a[i + 1])) {
temp = a[i];
temp2 = a[i + 1];
a[i + 1] = temp;
a[i] = temp2;
}
}
if(checkThreadLogistic(a)){
engine=false;
}
}
return a;
}
private static boolean checkThreadLogistic(int[] a) {
return checkCertainElement(a);
}
private static boolean checkCertainElement(int[] a) {
for(int i=0;i<a.length;i++){
if(i>1){
for(int j=a.length;j>i;j--){
if(j<a.length) if(a[i]>a[j])return false;
}
}
}
return true;
}
public static void checkArray(int[]array){
for (int anArray : array) {
System.out.println(anArray + "");
}
}
}
=is assignment,==is equality. This is why you should always just writewhile (!sorted)instead. It protects you from this sort of typo.whileloop doesn't ever execute the loop body at all, because of what azurefrog points out above. If you fix that, it will only ever run once, because you setsorted = trueunconditionally at the end of the loop.==in my actual code but messed it up while typing it on here.