I am learning java from basics and I set the initial objective to build a base changer by my self but I am lost at this:
when its gonna do: numero=numero+(mult*c)
initially numero is 0
, c
is 4
and mult
is 1
and then next numero becomes 52
instead of 4
, maybe I am mixing Strings and int?
public class nintodec {
public static void main(String[] args) {
int number;
System.out.println("enter base nine number");
number = 1234;
int num = number;
String cadena = "";
int numero = 0;
cadena = String.valueOf(num);
cadena = Integer.toString(num);
String reverse = new StringBuffer(cadena).reverse().toString();
int mult = 1;
for (int i = 0; i < reverse.length(); i++) {
char c = reverse.charAt(i);
System.out.println(" c:" + c + " mult:" + mult);
numero = numero + (mult * c);
System.out.println(" numero" + numero);
mult = mult * 9;
}
System.out.println(numero);
//when its gonna do: `numero=numero+(mult*c)` initially numero is 0, c is 4 and mult is 1 and then next numero becomes 52 instead of 4
any help please?