Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- public class task1 {
- public static boolean booleanExpression (boolean a, boolean b, boolean c, boolean d) {
- byte cout = 0;
- if (a == true) {cout++}
- if (b == true) {cout++}
- if (c == true) {cout++}
- if (d == true) {cout++}
- if (cout == 2) {
- return true;
- } else {
- return false;
- }
- }
- public static int leapYearCount (int year) {
- int cout = 0;
- for (i = 4; i <= year; i += 4) {
- if (i % 100 == 0) && (i % 400 != 0) {cout++};
- }
- return cout;
- }
- static int flipBit (int value, int bitIndex) {
- return value ^ (1 « (bitIndex - 1));
- }
- public static boolean isPowerOfTwo (int value) {
- if (value - ~value == 1) {
- return true;
- } else {
- return false;
- }
- }
- public static boolean isPalindrome (String text) {
- String replaceText = text.toLowerCase().replaceAll("[^a-zA-Z0-9]", "");
- String reverseText = new StringBuilder(replaceText).reverse().toString();
- return replaceText.equals(reverseText);
- }
- public static BigInteger factorial (int value) {
- if (value == 0) {
- return 1;
- }
- BigInteger result = 1;
- for(value; value > 0; value--) {
- result *= value;
- }
- return result;
- }
- public static int[] mergeArrays (int[] a1, int[] a2) {
- if (a1 == null) {
- if (a2 == null) {
- return a1;
- } else {
- return a1;
- }
- } else {
- return a2;
- }
- int i = 0, j = 0, k = 0;;
- size = a1.length + a2.length;
- int[] result = new int[size];
- for (k; k <= size;)
- if (i > a1.length) {
- for (j; j <= a2.length) {
- result[k] = a2[j];
- j++;
- k++;
- }
- } else {
- if (j > a2.length) {
- result[k] = a1[i];
- i++;
- k++;
- }
- } else {
- if (a1[i] <= a2[j]) {
- result[k] = a1[i];
- i++;
- k++;
- } else {
- result[k] = a2[j];
- j++;
- k++;
- }
- }
- return result;
- }
- public static void main (String[] args) {
- System.out.println(booleanExpression(true, true, true, true));
- System.out.println(leapYearCount(2019));
- System.out.println(flipBit(200, 3));
- System.out.println(isPowerOfTwo(16));
- System.out.println(isPalindrome("BiGDadgIb"));
- System.out.println(factorial(10));
- System.out.println(mergeArrays({0, 2, 2}, {1, 3}));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement