Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- class Lesson_1011_Activity{
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter a number in base 8:");
- int input = scan.nextInt();
- boolean illegalDigit = false;
- int temp = input;
- int octalexponent = 0;
- int sum = 0;
- while (temp > 0)
- {int digit = temp % 10;
- temp /=10;
- if (digit >7)
- illegalDigit = true;
- sum += digit * Math.pow(8,octalexponent);
- octalexponent++;
- }
- if (input > 77777777)
- {System.out.println("ERROR: Incorrect Octal Format");}
- else if (illegalDigit == true)
- {System.out.println("ERROR: Incorrect Octal Format");
- }
- else
- {System.out.println(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement