Pefect Number

package co.akds;

public class PerfectNumber {

    public static void main(String[] args) {
        System.out.println(isPerfectNumber(6));
        System.out.println(isPerfectNumber(28));
        System.out.println(isPerfectNumber(26));
    }

    private static boolean isPerfectNumber(int number) {

        /*
        Method calculates if the number is perfect. If yes, it 
		returns value TRUE, if no FALSE. Number is perfect when 
		the sum of it's divisors equals number supplied (excluding 
		number itself).
		
        Examples:
            isPerfectNumber(6) 1 -> True  / 1 + 2 + 3 = 6
            isPerfectNumber(28) -> True  / 1 + 2 + 4 + 7 + 14 = 28
            ifPerfectNumber(26) -> False / 1 + 2 + 13 = 16
         */

        boolean result = false;

        if (number < 1) {
            return result;
        }

        int sum = 0;
        for (int i = 1; i < number - 1; i++) {
            if (number % i == 0) {
                sum += i;
            }
        }
        if (sum == number) {
            result = true;
        }
        return result;
    }
}

Diagonal Star

package co.akds;

public class DiagonalStar {
    public static void main(String[] args) {

        // Test

        printSquareStar(5);
    }
    public static void printSquareStar (int number) {
        /*
        This method prints a rectangle with 2 diagonals.
        Minimum size is 5x5.
        If parameter supplied is less than 5, it returns "Invalid Value".
		
        Examples:
            printSquareStar(5);
            Output:
                        *****
                        ** **
                        * * *
                        ** **
                        *****
            printSquareStar(8);
			Output:
                        ********
                        **    **
                        * *  * *
                        *  **  *
                        *  **  *
                        * *  * *
                        **    **
                        ********
         */

        if (!(number < 5)) {
            for (int i=0; i<=number-1;i++) {
                for (int j=0; j<=number-1; j++) {
                    if (i == j || i == 0 || j == 0 || j == number -1 || 
					i == number - 1|| j == number - i - 1) {
                        System.out.print("*");
                    } else {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        } else {
            System.out.println("Invalid Value");
        }
    }
}

Flour packer

package co.akds;

public class FlourPacker {

    public static void main(String[] args) {
        System.out.println(canPack(1, 0, 4));
        System.out.println(canPack(1, 0, 5));
        System.out.println(canPack(0, 5, 4));
        System.out.println(canPack(2, 2, 12));
        System.out.println(canPack(-3, 2, 12));
    }

    public static boolean canPack(int bigCount, int smallCount, int goal) {

        /*
        Method canPack takes in bigCount and smallCount parameters and they
		represent 5kg and 1kg packaging respectively. Goal parameter is the
		amount that needs to be packed, but no remainder can be left.
		Packaging is either full or empty. In other words: If 4kg needs to 
		be packed, 5kg bag can't be used.
        
		Examples:
            canPack(1,0,4)   -> false  - 4kg doesn't fit perfectly into 5kg bag.
            canPack(1,0,5)   -> true   - 5kg does fit perfectly into 5kg bag.
            canPack(0,5,4)   -> true   - 4kg can be packed perfectly into 4x1kg bags (1 bag spare)
            canPack(2,2,12)  -> true   - 10kg packed in 5kg bags and 2kg packed in 1kg bags, perfect fit.
            canPack(-3,2,12) -> false  - negative number of big bags, method returns false
         */

        boolean result = false;

        // Making sure negative values are not accepted

        if (bigCount < 0 || smallCount < 0 || goal <= 0) {
            return result;
        }

        int availablePackaging = (bigCount * 5) + smallCount;

        // Making sure if not enough packaging, method will return false

        if (goal > availablePackaging) {
            return result;
        } else {
            // If packaging equals exactly the amount of goal, returning true
            if (goal == availablePackaging) {
                result = true;
            } else {
                // Returning true only if packaging fits the goal with no remainder
                if (goal / 5 < 1 && !(smallCount >= goal)) {
                    return result;
                } else if ((goal / 5 > 1) || (smallCount >= goal)) {
                    int remainingGoal = goal - ((goal / 5) * 5);
                    if (smallCount >= remainingGoal) {
                        result = true;
                    }
                } else if (goal % 5 == 0) {
                    if (bigCount *5 >= goal) {
                        result = true;
                    }
                }
            }
            return result;
        }
    }
}

Kilobytes -> Megabytes Converter

package co.akds;

public class MegabytesAndKilobytesConverter {

    public static void main(String[] args) {

        /*
        Function converts amount of Kilobytes supplied (parameter) into 
		the amount of MB and remainder Kilobytes.
		
        Examples:
            printMegaBytesAndKiloBytes(100)  -> 0 MB and 100 KB
            printMegaBytesAndKiloBytes(1024) -> 1 MB and 0 KB
            printMegaBytesAndKiloBytes(1300) -> 1 MB and 276 KB
         */

        // Testing

        printMegaBytesAndKiloBytes(100);
        printMegaBytesAndKiloBytes(1024);
        printMegaBytesAndKiloBytes(1025);
        printMegaBytesAndKiloBytes(1300);
        printMegaBytesAndKiloBytes(2048);
        printMegaBytesAndKiloBytes(2050);
    }

    private static void printMegaBytesAndKiloBytes (int kiloBytes) {
        if(kiloBytes < 0) {
            System.out.println("Invalid Value, only positive values allowed");
        } else {
            int megaBytes = kiloBytes / 1024;
            if (megaBytes == 0) {
                System.out.println(kiloBytes + " KB = " + megaBytes + 
				" MB and " + kiloBytes + " KB");
            } else {
                int remainder = kiloBytes - (megaBytes * 1024);
                System.out.println(kiloBytes + " KB = " + megaBytes + 
				" MB and " + remainder + " KB");
            }
        }
    }
}