Hello everyone,
There is something wrong with the method toBinary(int)
pls, gimme a hint.
Thank you in advance!

package en.codegym.task.pro.task09.task0906;
/*
Binary converter
*/
public class Solution {
public static void main(String[] args) {
int decimalNumber = Integer.MAX_VALUE;
System.out.println("Decimal number " + decimalNumber + " is equal to binary number " + toBinary(decimalNumber));
String binaryNumber = "1111111111111111111111111111111";
System.out.println("Binary number " + binaryNumber + " is equal to decimal number " + toDecimal(binaryNumber));
}
public static String toBinary(int decimalNumber) {
String output = "";
int input = decimalNumber;
if (input > 0) {
while (input != 0) {
output += input % 2;
input /= 2;
}
return output;
} else {
return "";
}
}
public static int toDecimal(String binaryNumber) {
int decim = 0;
if (binaryNumber == null) {
return decim;
} else {
for (int i = 0; i < binaryNumber.length(); i++) {
int j = 0;
decim += decim + (int) (Integer.parseInt(String.valueOf(binaryNumber.charAt(i))) * Math.pow(2, j++));
}
return decim;
}
}
}