In the "toInteger()" methode , why the output of k is always a random number ??? I don't understand
import java.util.Scanner; //your code goes here public class Converter { //Methode to convert a number to binary numbre public static int toBinary(int x){ String binary=""; while(x > 0) { binary = (x%2)+binary; x /= 2; } return toInteger(binary) ; } //to convert String to Integer public static int toInteger (String ch){ int k =0 ; int a=1; //System.out.println(ch.length()); for(int i=0 ; i<ch.length() ; i++){ k = k*a ; k += ch.charAt(i) ; a*=10; } return k ; } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); System.out.print(Converter.toBinary(x)); } }