Tuesday, 13 August 2013

Java To Pascal Example

Java To Pascal Example

I'm new to programming and I don't understand Java at all. Below there's
code in Java that I can't figure out in Pascal:
public static boolean verificaRS(String numeroRS)
{
Integer numeroAbsoluto = Integer.valueOf(0);
Integer resto = Integer.valueOf(0);
Integer numero = Integer.valueOf(0);
int numeroAuxiliar = 1000000000;
int soma = 0;
try
{
numero = Integer.valueOf(Integer.parseInt(numeroRS));
} catch (Exception ex) {
Log.escreveLog(ex.toString());
return false;
}
if (numero.intValue() > 0)
{
for (int contador = 9; contador > 1; contador--) {
numeroAuxiliar /= 10;
resto = Integer.valueOf(numero.intValue() % numeroAuxiliar);
numeroAbsoluto = Integer.valueOf(numero.intValue() / numeroAuxiliar);
numero = Integer.valueOf(numero.intValue() -
numeroAbsoluto.intValue() * numeroAuxiliar);
soma += numeroAbsoluto.intValue() * contador;
}
if (soma % 11 == numero.intValue())
return true;
if ((soma % 11 == 10) && (numero.intValue() == 0)) {
return true;
}
return false;
}
return false;
}
}
Somebody can help me translate? So far this is what I did:
NumeroAbsoluto, Resto, Numero, NumeroAuxiliar, Soma: Integer;
Contador: Integer;
begin
numeroAuxiliar:= 1000000000;
Numero:=00009356332;
for Contador :=9 downto 1 do
begin
NumeroAuxiliar:=NumeroAuxiliar div 10;
Resto:=Numero mod NumeroAuxiliar;
NumeroAbsoluto:=Numero div NumeroAuxiliar;
Numero:= Numero - NumeroAbsoluto * NumeroAuxiliar;
Soma:=Soma + NumeroAbsoluto * Contador;
end;
The numero in this case is 00009356332. But in the end, the result is not
the same.

No comments:

Post a Comment