Advertisement
The_Lost

Untitled

Dec 8th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | None | 0 0
  1. import java.io.File;
  2.  
  3. public class task1 {
  4.    
  5.     public static boolean booleanExpression (boolean a, boolean b, boolean c, boolean d) {
  6.    
  7.         byte cout = 0;
  8.         if (a == true) {cout++}
  9.         if (b == true) {cout++}
  10.         if (c == true) {cout++}
  11.         if (d == true) {cout++}
  12.         if (cout == 2) {
  13.             return true;
  14.         } else {
  15.             return false;
  16.         }
  17.     }
  18.    
  19.     public static int leapYearCount (int year) {
  20.        
  21.         int cout = 0;
  22.         for (i = 4; i <= year; i += 4) {
  23.             if (i % 100 == 0) && (i % 400 != 0) {cout++};
  24.         }
  25.         return cout;
  26.     }
  27.    
  28.     static int flipBit (int value, int bitIndex) {
  29.         return value ^ (1 « (bitIndex - 1));
  30.     }
  31.    
  32.     public static boolean isPowerOfTwo (int value) {
  33.        
  34.         if (value - ~value == 1) {
  35.             return true;
  36.         } else {
  37.             return false;
  38.         }
  39.     }
  40.    
  41.     public static boolean isPalindrome (String text) {
  42.        
  43.         String replaceText = text.toLowerCase().replaceAll("[^a-zA-Z0-9]", "");
  44.         String reverseText = new StringBuilder(replaceText).reverse().toString();
  45.         return replaceText.equals(reverseText);
  46.     }
  47.    
  48.     public static BigInteger factorial (int value) {
  49.        
  50.         if (value == 0) {
  51.             return 1;
  52.         }
  53.        
  54.         BigInteger result = 1;
  55.         for(value; value > 0; value--) {
  56.             result *= value;
  57.         }
  58.         return result;
  59.     }
  60.    
  61.     public static int[] mergeArrays (int[] a1, int[] a2) {
  62.        
  63.         if (a1 == null) {
  64.             if (a2 == null) {
  65.                 return a1;
  66.             } else {
  67.                 return a1;
  68.             }
  69.         } else {
  70.             return a2;
  71.         }
  72.        
  73.         int i = 0, j = 0, k = 0;;
  74.         size = a1.length + a2.length;
  75.         int[] result = new int[size];
  76.        
  77.         for (k; k <= size;)
  78.             if (i > a1.length) {
  79.                 for (j; j <= a2.length) {
  80.                     result[k] = a2[j];
  81.                     j++;
  82.                     k++;
  83.                 }
  84.             } else {
  85.                 if (j > a2.length) {
  86.                     result[k] = a1[i];
  87.                     i++;
  88.                     k++;
  89.                 }
  90.             } else {
  91.                 if (a1[i] <= a2[j]) {
  92.                     result[k] = a1[i];
  93.                     i++;
  94.                     k++;
  95.                 } else {
  96.                     result[k] = a2[j];
  97.                     j++;
  98.                     k++;
  99.                 }
  100.             }
  101.         return result;
  102.     }
  103.    
  104.     public static void main (String[] args) {
  105.        
  106.         System.out.println(booleanExpression(true, true, true, true));
  107.        
  108.         System.out.println(leapYearCount(2019));
  109.        
  110.         System.out.println(flipBit(200, 3));
  111.        
  112.         System.out.println(isPowerOfTwo(16));
  113.        
  114.         System.out.println(isPalindrome("BiGDadgIb"));
  115.        
  116.         System.out.println(factorial(10));
  117.        
  118.         System.out.println(mergeArrays({0, 2, 2}, {1, 3}));
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement