<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    dream.in.java

    能以不變應(yīng)萬變是聰明人做事的準(zhǔn)則。萬事從小事做起,積累小成功,問鼎大成功,是成功者的秘訣。

    計算某個方法的執(zhí)行時間

     

     1 package assemblyLanguage;
     2 import java.math.BigInteger;
     3 import java.util.Date;
     4 import java.util.Scanner;
     5 
     6 
     7 public class Add {
     8 
     9     /**
    10      * @param args
    11      * Write a complete 8086 assembly language program to calculate and display the value of the expression:  
    12      * "1 + (2+2) + 3 + (4+4) + 5 + (6+6) + 7 + 9 + (10+10) + 11 ++ N".
    13      *  Notice the fact that the even numbers are added twice. 
    14      *  N should be input from the keyboard. A LOOP structure is required.
    15      *   Use a pseudocode or flowchart to sketch your ideas and plan the overall logic 
    16      *   before you write the program. 
    17      
    18     static int  add(int n)
    19     {
    20         int result = 0;
    21         for(int i = 1; i <= n; i++)
    22         {
    23             int temp = i;
    24             if(temp % 2 == 0)
    25                 {
    26                 temp *=2;
    27                 }
    28             result += temp;
    29                 
    30         }
    31         return result;
    32     }
    33     */
    34     static BigInteger add(BigInteger n) throws Exception
    35     {
    36         BigInteger result = new BigInteger("0"),
    37                     TWO = new BigInteger("2");
    38         BigInteger temp = null;
    39         for(BigInteger i = BigInteger.ONE; i.compareTo(n) <= 0; i=i.add(BigInteger.ONE))
    40         {
    41             temp = i;
    42             if(temp.remainder(TWO).compareTo(BigInteger.ZERO) == 0)
    43                 {
    44                 temp=temp.multiply(TWO);
    45 //                temp=temp.add(temp);
    46                 }
    47             result = result.add(temp);
    48                 
    49         }
    50         return result;
    51     }
    52     public static void main(String[] args) throws Exception {
    53         // TODO 自動生成方法存根
    54         
    55         Scanner reader = new Scanner(System.in);
    56         System.out.print("Please input an integer: ");
    57         BigInteger a = reader.nextBigInteger();
    58         System.out.print("1+(2+2)+3+(4+4)+5++N(N=" + a.toString() + ")= ");
    59         Date date1 = new Date();
    60         System.out.println(add(a).toString());
    61         Date date2 = new Date();
    62         long totalTime = date2.getTime() - date1.getTime();
    63         System.out.println("用時:"+ totalTime+"ms"); 
    64 
    65     }
    66 
    67 }
    68 

     

    posted on 2008-12-20 00:32 YXY 閱讀(673) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 久久久久久国产a免费观看不卡| 亚洲人成未满十八禁网站| 国产成人yy免费视频| a级毛片免费在线观看| 亚洲AV成人无码久久WWW| 亚洲综合综合在线| 亚洲视频免费在线播放| 亚洲成网777777国产精品| 国产精品视频免费一区二区三区| 中文字幕乱码一区二区免费| 一个人看的www免费高清| 福利片免费一区二区三区| 思思久久99热免费精品6| 国产亚洲精品成人AA片| 亚洲精品无码不卡在线播放| 亚洲乱色伦图片区小说| 亚洲永久网址在线观看| 国产亚洲漂亮白嫩美女在线| 国产精品观看在线亚洲人成网| 亚洲日本国产综合高清| 欧洲美女大片免费播放器视频| 性色av极品无码专区亚洲 | 一级做a爰片久久免费| a级毛片无码免费真人久久| 91在线老王精品免费播放| 在线视频精品免费| 日本无吗免费一二区| 中文字幕亚洲一区| 亚洲第一页在线观看| 色天使色婷婷在线影院亚洲| 国产成人精品免费视频大全| 伊人久久免费视频| 成年女人毛片免费观看97| 亚洲亚洲人成综合网络| 亚洲欧美日韩久久精品| 13小箩利洗澡无码视频网站免费| 毛片a级毛片免费播放下载 | 亚洲av无码一区二区三区四区| 久久九九免费高清视频| 国产成人精品免费视频大| 精品国产精品久久一区免费式|