Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3.  
  4. class Lesson_1011_Activity{
  5. public static void main(String[] args)
  6. {
  7. Scanner scan = new Scanner(System.in);
  8. System.out.println("Enter a number in base 8:");
  9. int input = scan.nextInt();
  10.  
  11. boolean illegalDigit = false;
  12. int temp = input;
  13. int octalexponent = 0;
  14. int sum = 0;
  15.  
  16. while (temp > 0)
  17. {int digit = temp % 10;
  18. temp /=10;
  19. if (digit >7)
  20. illegalDigit = true;
  21. sum += digit * Math.pow(8,octalexponent);
  22. octalexponent++;
  23.  
  24. }
  25.  
  26. if (input > 77777777)
  27. {System.out.println("ERROR: Incorrect Octal Format");}
  28. else if (illegalDigit == true)
  29. {System.out.println("ERROR: Incorrect Octal Format");
  30. }
  31. else
  32. {System.out.println(sum);
  33.  
  34. }
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement