Convert decimal to binary and vice-versa in Java
The best way to do it:

static String convertDecimalToBinary(String decimal) {
    return Integer.toString(Integer.parseInt(decimal, 10), 2);
}

static int convertBinaryToDecimal(String binary) {
    return Integer.parseInt(binary, 2);
}


By the way your code looks good except for at least two issues:


Don't work with negative numbers
The method isDecimalOrBinary is ambiguous: what's the result of the 100 input? It's binary of course, but if i meant one hundred? I suggest to delegate the user to specify it.


I would correct it in this way:

import java.util.Scanner;

public class BinaryToDecimalAndBackConverter {

    static String convertDecimalToBinary(String decimal) {
        final boolean isNegative = decimal.startsWith("-");
        if (isNegative) {
            decimal = decimal.substring(1);
        }

        int integer = Integer.valueOf(decimal);
        String result = new String();

        while (integer &gt; 0) {
            result += String.valueOf(integer % 2);
            integer /= 2;
        }

        // use StringBuilder instead of StringBuffer, we are sure about
        // exclusive access, no need to use a thread safe class
        final StringBuilder resultBuilder = new StringBuilder(result);
        if (isNegative) {
            resultBuilder.append("-");
        }

        return resultBuilder.reverse().toString();
    }

    static int convertBinaryToDecimal(String binary) {
        final boolean isNegative = binary.startsWith("-");
        if (isNegative) {
            binary = binary.substring(1);
        }
        int result = 0;

        for (int reverseCounter = 0; reverseCounter &lt; binary.length(); reverseCounter++) {
            final char currentChar = binary.charAt(binary.length() - reverseCounter - 1);
            final int numericValue = Character.getNumericValue(currentChar);
            result += Math.pow(2, reverseCounter) * numericValue;
            // System.out.println(Math.pow(2, reverseCounter) *
            // Character.getNumericValue(binary.charAt(binary.length() -
            // reverseCounter - 1)) + " reverseCounter " + reverseCounter);
        }

        if (isNegative) {
            result = -result;
        }

        return result;
    }

    public static void main(String[] args) {
        final Scanner inputScanner = new Scanner(System.in);

        System.out.print("Please enter the binary/decimal number to convert:");
        // expected input: NUM D|B
        final String[] splittedInput = inputScanner.nextLine().split(" ");
        if (splittedInput.length != 2) {
            // don't forget to close the Scanner
            inputScanner.close();
            throw new IllegalArgumentException("Wrong input format: expected NUM D|B");
        }
        final String input = splittedInput[0];

        switch (splittedInput[1]) {
        case "d":
        case "D":
            System.out.println(convertDecimalToBinary(input));
            break;
        case "b":
        case "B":
            System.out.println(convertBinaryToDecimal(input));
            break;
        default:
            // don't forget to close the Scanner
            inputScanner.close();
            throw new IllegalArgumentException(
                    "Wrong input format: expected NUM D|B, the second argument was not D nor B");
        }

        // don't forget to close the Scanner
        inputScanner.close();
    }
}