DOC

import java

By Glen Lawson,2014-07-03 11:52
14 views 0
import java

import java.util.Scanner;

    public class Two

    {

     /**

     * @param args

     */

     public static void main(String[] args)

     {

     // TODO Auto-generated method stub

     Scanner input=new Scanner(System.in);

     System.out.println("Please input a number");

     int a=input.nextInt();

     System.out.println("Please input a number");

     int n=input.nextInt();

     try{

     System.out.println("2"+n+"次方="+power(a,n));

     }

    catch(Exception e)

    {

     System.out.println("2"+n+"次方>"+a);

     }

     }

     public static int power(int a,int n)throws Exception

     {

     int result=1;

     for(int i=1;i<=n;i++)

     if(result<=a/2)

     result*=2;

     else throw new Exception();

     return result;

     }

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com