Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package digitos;
/**
*
* @author Marvin Ferreira
* Cógido para obter dígitos de números inteiros.
*/
public class Digitos {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//obterDigitoV1();
//obterDigitoV2();
obterDigitoV3(5432,0);
obterDigitoV3(5432,1);
obterDigitoV3(5432,2);
obterDigitoV3(5432 ,3);
}
public static void obterDigitoV1(){
int n = 2450;
while (n>0){
int d = n / 10;
int k = n - d * 10;
n = d;
System.out.println(k + " ");
}
}
public static void obterDigitoV2(){
int num_1 = 2450;
while (num_1> 0){
int digit = num_1%10;
num_1 = num_1/10;
System.out.println(digit);
}
}
public static void obterDigitoV3(int valor, int digito){
Double potencia = Math.pow(10,digito);
int resultado = valor / potencia.intValue() % 10;
System.out.println(resultado);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.