So I am trying to change an octal to a regular base 10 number, but I can't understand where my code is supposed to go from here. What I tried to do was change the int into a string and then use the individual characters to create the base 10 numbers for each place, but it isn't working.
import java.util.Scanner;
import java.lang.Math;
class Lesson_1011_Activity{
public static void main(String[] args)
{
Scanner s = new Scanner (System.in);
System.out.println("Enter octal with less than 9 digits");
int octal = s.nextInt();
String ocStr = Integer.toString(octal);
int ocLen = ocStr.length();
int flag = 0;
int baseTen = 0;
char temp;
int power = ocLen - 1;
Double tempDub;
if (ocStr.contains("8") || ocStr.contains("9") || ocStr.length()>8){
flag++;
System.out.println("ERROR: Incorrect Octal Format");
}
if (flag<1){
for (int i = ocLen-1; i >0; i--){
temp = ocStr.charAt(i);
System.out.println(temp);
tempDub = 1.0*Character.getNumericValue(temp);
System.out.println(tempDub);
tempDub = java.lang.Math.pow(tempDub,power);
System.out.println(tempDub);
int tempInt = Integer.valueOf(tempDub.intValue());
System.out.println("Changed Character is: " + tempDub);
baseTen = baseTen + tempInt;
System.out.println("New answer so far is: " + baseTen);
power--;
}
System.out.println(baseTen);
}
}
}