Problem of the Day
A new programming or logic puzzle every Mon-Fri

Octal

Welcome to the first day of October! To honor the first day of October we'll be building a converter from octal to decimal. Your converter must have some sort of validation. For instance, 39 is not a valid octal number where as 31 is. If your function takes in 31 it should output 25.

Permalink: http://problemotd.com/problem/octal/

Comments:

  • nebyark - 10 years, 2 months ago

    #converts octal to decimal
    str = '8'
    while(int(str[len(str)-1])>7):
        str = raw_input("input valid octal number: ")
    sum = 0
    for i in range(0,len(str)):
        sum += int(str[i])*(8**(len(str)-(i+1)))
    print sum
    

    reply permalink

  • xConorrr - 10 years, 2 months ago

         do{
                try{
                System.out.print("\nEnter an octal number: ");
                Integer num = Integer.parseInt(in.nextLine(), 8);
                System.out.println("Decimal form: " +num);
                break;
                }catch(Exception e){
                    System.out.println("You must enter a valid octal number!");
                }
            }while(true);
    

    reply permalink

Content curated by @MaxBurstein