| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:第一次用java作题In Reply To:第一次用java作题 Posted by:kicker at 2004-09-18 23:12:34 搞不清为什么会 runtime error:
望高手指点一二
import java.io.*;
import java.math.*;
public class Main
{
public static void main(String argv[])
{
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
while(true)
{
try
{
String line = cin.readLine();
if(line == null)
break;
String [] strs=line.split("\\s\\s*");
int ia,in,k;
for(k=0,ia=-1,in=-1; k<strs.length; k++)
{
if(strs[k].length()!=0)
{
if(ia == -1)
{
ia = k;
}
else if(in == -1)
{
in = k;
}
}
}
BigDecimal a = new BigDecimal(strs[ia]);
BigDecimal res = new BigDecimal("1");
int n = Integer.parseInt(strs[in]);
while(n!=0)
{
res = res.multiply(a);
n--;
}
String resstr = res.toString();
int begin = 0;
int end = resstr.length();
if(resstr.charAt(0) == '0')
{
begin = 1;
}
while(resstr.charAt(end -1) == '0' || resstr.charAt(end -1) == '.')
{
end --;
if(resstr.charAt(end) == '.')
break;
}
System.out.println(resstr.substring(begin, end));
}
catch (Exception e)
{
}
}
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator