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 |
不行!!大侠帮忙看看!In Reply To:为何我的总是Runtime Error? (java) Posted by:sza at 2005-10-23 12:02:09 package computertransformation; import java.io.*; import java.util.*; import java.math.BigInteger; public class Main{ public static void main(String args[]) { String input; int number=0; BigInteger array[]=new BigInteger[1001]; for(int i=0;i<=1000;i++){ array[i]=new BigInteger("0"); } array[1]=new BigInteger("0"); array[2]=new BigInteger("1"); BigInteger one=new BigInteger("1"); BigInteger two=new BigInteger("2"); while(true){ try{ Scanner cin=new Scanner(System.in); if(cin==null) break; number=cin.nextInt(); } catch(Exception e){ break; } if(number==1){ System.out.println("0"); } else if(number==2){ System.out.println("1"); } else{ for(int i=3;i<=number;i++){ if(i%2==0) { array[i]=array[i-1].multiply(two); array[i]=array[i].add(one); } else { array[i]=array[i-1].multiply(two); array[i]=array[i].subtract(one); } } System.out.println(array[number]); } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator