what's wrong with my code? the first and second task requirement make me so confuse
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) {
//write your code here
//int st ;
String a=" ";
while(decimalNumber>0) {
a=decimalNumber%2 +a ;
//a=a+st;
decimalNumber=decimalNumber/2 ;
}
if(decimalNumber>0) {return a;}
else
return null;
}
public static int toDecimal(String binaryNumber) {
//write your code here
int tot=0;
char[] ch=new char[binaryNumber.length()] ;
for(int i=0;i<binaryNumber.length();i++) {
ch[i]= binaryNumber.charAt(i) ;
tot= tot+ch[i] *(int)Math. pow(2,i) ;
}
if(binaryNumber!="") {return tot;}
else
return 0;
}
}