/**
*Description:convert Oct to Dec
*Author:yemoo 2006.12.05
*/
public class P38{
int convertOct2Dec(String Oct){
int result = 0 ;
int power = 1 ;
for ( int i = Oct.length() - 1 ;i >= 0 ;i -- ,power *= 8 ){
char temp = Oct.charAt(i);
int intTemp = Character.getNumericValue(temp);
if (intTemp >= 0 && intTemp < 8 ){
result += intTemp * power;
} else {
if (temp == ' - ' && i == 0 ){
result =- result;
} else {
return result;
}
}
}
return result;
}
String readInput(){
KeyboardInput in = new KeyboardInput();
System.out.print( " Please input a october number: " );
return in.readString();
}
public static void main(String args[]){
P38 obj = new P38();
String oct = obj.readInput();
int value = obj.convertOct2Dec(oct);
System.out.println( " Oct: " + oct + " ==Dec: " + value);
}
}
*Description:convert Oct to Dec
*Author:yemoo 2006.12.05
*/
public class P38{
int convertOct2Dec(String Oct){
int result = 0 ;
int power = 1 ;
for ( int i = Oct.length() - 1 ;i >= 0 ;i -- ,power *= 8 ){
char temp = Oct.charAt(i);
int intTemp = Character.getNumericValue(temp);
if (intTemp >= 0 && intTemp < 8 ){
result += intTemp * power;
} else {
if (temp == ' - ' && i == 0 ){
result =- result;
} else {
return result;
}
}
}
return result;
}
String readInput(){
KeyboardInput in = new KeyboardInput();
System.out.print( " Please input a october number: " );
return in.readString();
}
public static void main(String args[]){
P38 obj = new P38();
String oct = obj.readInput();
int value = obj.convertOct2Dec(oct);
System.out.println( " Oct: " + oct + " ==Dec: " + value);
}
}