Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1.  public static void main(String[] args) {
  2.         //part 1 - "Sortieren nur anders"
  3.         // length of the answer array = arr1
  4.         // if elements are in both arr's, then same folge
  5.         // what is not in arr2 - same folge, but in the end
  6.         //the elements from arr, that are not on the list, have to be written in the order in which they stay in arr
  7.         //TODO print out such elements correctly
  8.         otherSort(new int [] {2,3,1,3,2,4,123,6,7,9,2,19}, new int [] {2,1,4,123,3,9,6});
  9.     }
  10.     Scanner in = new Scanner(System.in);
  11.     public static int[] otherSort(int[] arr, int[] arr2) {
  12.         System.out.print("{");
  13.         int number = 0;
  14.         //elements e ARR, e ARR2
  15.         for (int i = 0; i < arr2.length; i++) {
  16.             for (int j = 0; j < arr.length; j++) {
  17.                 if (arr[j] == arr2[i]) {
  18.                     System.out.print(arr[j] + ",");
  19.                     number++;
  20.                 }
  21.             }
  22.         }
  23.         //scheisse hier (da unten)
  24.         int []  numbers = new int [arr.length];
  25.         for (int i = 0; i < arr2.length; i++) {
  26.             for (int j = 0; j < arr.length; j++) {
  27.                 if (arr[j] == arr2[i]) {
  28.                     numbers[i] = arr[j];
  29.                 }
  30.             }
  31.         }
  32.         int notNull = 0;
  33.         for (int i = 0; i < number; i++){
  34.             if (numbers[i] != 0){
  35.                 notNull++;
  36.             }
  37.         }
  38.         int y = 0;
  39.         for (int j = 0; j < arr.length; j++){
  40.             for (int i : numbers){
  41.                 //   System.out.print(i + " " + j);
  42.                 if (i != 0) {
  43.                     if (arr[j] != i && arr[j] /i != 0 && arr[j] % i != 0) {
  44.                         y++;
  45.                     }
  46.                     if (y == notNull){
  47.                         System.out.print(arr[j] + ",");
  48.                         y = 0;
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.         System.out.print("}");
  54.         return new int[]{};
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement