Posted on 2006-12-05 11:34
Yemoo'S Java Blog 阅读(2027)
评论(0) 编辑 收藏 所属分类:
JAVA个人敝作
/**
*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);
}
}