Untitled

mail@pastecode.io avatar
unknown
java
15 days ago
1.6 kB
435
Indexable
Never
class Main {
    public static void functionIsWorkingFineOrNot(){
        int num = 45;
        boolean ans = isEven(num);

        if(ans == true){
            System.out.println("This function is not working fine");
        }

        num = 40;
        ans = isEven(num);

        if(ans == false){
            System.out.println("This function is not working fine");
        }
    }

    public static boolean isEven(int num){
        if(num % 2 == 0){
            return true;
        } else {
            return false;
        }
    }


    public static int reverseNumber(int num){
        int reversedNumber = 0;

        while(num > 0){
            int lastDigit = num%10;
            num = num/10;

            reversedNumber = reversedNumber*10 + lastDigit;
        }

        return reversedNumber;
    }

    public static boolean isPallindrome(int num){
        int reversedNumber = reverseNumber(num);

        if(reversedNumber == num){
            return true;
        } else {
            return false;
        }
    }

    public static int sumOfDigit(int num){
        int sum = 0;

        while(num > 0){
            // retrieve last digit
            int lastDigit = num%10;

            // delete last digit
            num = num/10;

            // add this digit to sum
            sum = sum + lastDigit;
        }

        return sum;
    }

    public static void main(String[] args) {
        int a = 5;
        int b = 10;

        swap(a,b);

        System.out.println(a);
        System.out.println(b);
    }

    public static void swap(int a, int b){
        int temp = a;
        a = b;
        b = temp;
    }
}
Leave a Comment