<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)萬(wàn)變是聰明人做事的準(zhǔn)則。萬(wàn)事從小事做起,積累小成功,問(wèn)鼎大成功,是成功者的秘訣。

    計(jì)算某個(gè)方法的執(zhí)行時(shí)間

     

     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 自動(dòng)生成方法存根
    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("用時(shí):"+ totalTime+"ms"); 
    64 
    65     }
    66 
    67 }
    68 

     

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


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲美女色在线欧洲美女| 亚洲欧洲久久久精品| 亚洲黄色三级视频| 久久精品视频免费看| 亚洲va久久久噜噜噜久久天堂| 国产免费黄色无码视频| 亚洲中文字幕无码中文字在线| www成人免费观看网站| 国产成人精品日本亚洲专区| 国产免费久久精品丫丫| 亚洲AV无码一区二区乱子伦| 久9久9精品免费观看| 亚洲黄色网址大全| 国产又黄又爽又猛免费app| 亚洲愉拍一区二区三区| 手机看片久久国产免费| a免费毛片在线播放| 亚洲AV无码第一区二区三区| h片在线免费观看| 亚洲AV日韩综合一区尤物| 日韩免费视频播放| 一级毛片免费视频网站| 久久亚洲精品中文字幕| 青春禁区视频在线观看直播免费| 亚洲国产成人AV网站| 国产精品亚洲αv天堂无码| 久久成人免费电影| 亚洲精品伊人久久久久 | 小草在线看片免费人成视久网| 亚洲欧洲日韩国产综合在线二区| 男人的好看免费观看在线视频| 国产亚洲精品美女2020久久| 亚洲乳大丰满中文字幕| 国产一卡二卡3卡四卡免费| 一级毛片免费不卡直观看| 亚洲黄色免费在线观看| 免费a在线观看播放| 99久久免费观看| 国产亚洲综合视频| 亚洲精品国产成人专区| 国产一级特黄高清免费大片|