HDOJ 2007 Java

兩個坑

1.  輸入的m,n 並不一定是按順序排列

2. Math.pow 返回一個double 類型,要進行強制類型轉換 

import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner sr=new Scanner(System.in);
        while(sr.hasNext()) {
            int start = sr.nextInt();
            int end = sr.nextInt();
            if(end <= start){
                int num = end;
                end = start;
                start = num;
            }
            long  pow2 = 0;
            long pow3 = 0;
            for(int i = start; i <= end; i++){
                if(Judge(i)){
                    pow2  = pow2 + (long)Math.pow(i,2);
                }
                else{
                    pow3 = pow3 + (long)Math.pow(i,3);
                }
            }
            System.out.println(pow2 + " " + pow3);
        }
    }
    public static boolean Judge(int value){
        if(value % 2 == 0){
            return true;
        }else{
            return false;
        }
    }
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章