In: Computer Science
java program that coverts base13 to decimal. without using array and methods.
import java.util.Scanner;
public class ConvertToDecimal {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a Base 13 string: ");
String base13 = in.next();
int decimal = 0;
char digit;
for (int i = 0; i < base13.length(); i++) {
digit = base13.charAt(i);
decimal *= 13;
if (digit >= '0' && digit <= '9')
decimal += digit - '0';
else if (digit == 'a' || digit == 'A')
decimal += 10;
else if (digit == 'b' || digit == 'B')
decimal += 11;
else if (digit == 'c' || digit == 'C')
decimal += 12;
}
System.out.println("The decimal number for " + base13 + " is " + decimal);
}
}
