Created
February 11, 2020 16:37
-
-
Save parzibyte/be1902ca099c6e8503f74d8a8e8176e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Programado por Luis Cabrera Benito | |
____ _____ _ _ _ | |
| _ \ | __ \ (_) | | | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___ | |
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \ | |
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/ | |
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___| | |
__/ | __/ | | |
|___/ |___/ | |
Blog: https://parzibyte.me/blog | |
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/ | |
Contacto: https://parzibyte.me/blog/contacto/ | |
*/ | |
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Escribe el octal:"); | |
String octal = sc.nextLine(); | |
long decimal = octalADecimal(octal); | |
System.out.printf("El octal %s es %d en decimal", octal, decimal); | |
} | |
public static long octalADecimal(String octal) { | |
long decimal = 0; | |
int potencia = 0; | |
for (int x = octal.length() - 1; x >= 0; x--) { | |
int valorActual = Character.getNumericValue(octal.charAt(x)); | |
long elevado = (long) Math.pow(8, potencia) * valorActual; | |
decimal += elevado; | |
potencia++; | |
} | |
return decimal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment