Guest User

Untitled

a guest
Oct 16th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. package Trabajo;
  2.  
  3. public class DecimalAOctal {
  4. public static void main(String[] args) {
  5. octalADecimal("20");
  6. }
  7. public static void octalADecimal(String base) {
  8. String cadenaInver = "";
  9. int b = 0;
  10. double c = 0;
  11. for (int i = base.length()-1; i >= 0; i--) {
  12. cadenaInver += ""+base.charAt(i);
  13. }
  14.  
  15. for (int i = 0; i < cadenaInver.length(); i++) {
  16. String convertir = "" + cadenaInver.charAt(i);
  17. b = Integer.parseInt(convertir);
  18. c += (b * Math.pow(8, i));
  19.  
  20. }
  21. System.out.println(c);
  22. }
  23.  
  24. }
Add Comment
Please, Sign In to add comment