Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. // Roman Kungurov
  2. // Exercise 1
  3. public static void main(String[] args) {
  4.         int[] num = new int[10];
  5.         int amount = 0;
  6.         for(int i=0; i<10; i++) {
  7.             if(Check(num[i]) == 1)
  8.                 amount++;
  9.         }
  10.         System.out.println("There are " + amount + " zehe numbers");
  11.     }
  12.     public static int Check(int num) {
  13.         int i=0;
  14.         int num1 = num;
  15.         while(num > 0) {
  16.             num /= 10;
  17.             i++;
  18.         }
  19.         for(int j=0; j < i; j++) {
  20.             if(!(i == num1%10))
  21.                 return 0;
  22.             num1 /= 10;
  23.         }
  24.         return 1;
  25.     }
  26.  
  27. // Exercise 2
  28. public static int Reflection(int num) {
  29.         return num*100+(num%10)*10+num/10;
  30.     }
  31.  
  32. // Exercise 3
  33. public static int[] newArr(int[] oldArr) {
  34.         int n = oldArr.length;
  35.         int[] newArr = new int[n];
  36.         for(int i=0; i<n; i++) {
  37.             int count =0;
  38.             for(int j=i+1; j < n; j++) {
  39.                 if(oldArr[j] > oldArr[i])
  40.                     count++;
  41.             }
  42.             newArr[i] = count;
  43.         }
  44.         return newArr;
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement