I was given an exercise so that in Java I could do a program that read a multi-digit integer and a position; and then show on the screen the number of the number that is in the indicated position. For example, for number 1234 position 1 should return the value 4, 2: 3, 3: 2, 4: 1. I can do it for a certain amount of numbers without problem, but I need the program to take any integer of any number of digits and show what is requested. It only occurred to me to divide the number by 10 ^ given position and then discard the rest, the problem with this is that I do not know how to make powers in java and I have only seen alternative structures until now. This is the code I use for 3 figures, I do not see how to do it for more figures without using powers.
public static int cifraInt(int numero,int posicion){
//Modulo que lee un entero y su posicion y retorna el digito que se encuentra
//en la posicion elegida
int cent, dec, uni, digito;
cent= numero/100;
dec=numero/10-cent*10;
uni=numero-cent*100-dec*10;
switch (posicion){
case 1: digito=cent;
break;
case 2: digito=dec;
break;
case 3: digito= uni;
break;
default: digito=-1;
}
return digito;