码迷,mamicode.com
首页 > 编程语言 > 详细

算法之路——POJ刷题(Java,持续更新中)

时间:2015-01-26 01:21:42      阅读:1209      评论:0      收藏:0      [点我收藏+]

标签:

先拿一些水题来练手了

1.POJ1000

import java.util.Scanner;

/**
 * Created by mxcsky on 2015/1/25.
 */
public class POJ1000 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        System.out.println(a + b);
    }
}

2.POJ1003

import java.util.Scanner;

/**
 * Created by mxcsky on 2015/1/25.
 */
public class POJ1003 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(true) {
            double m = in.nextDouble();
            double sum = 0.0;
            int i = 1;
            if (m < 0.00001) {
                System.exit(0);
            }
            if (m <= 0.5) {
                System.out.println("1 card(s)");

            } else {
                while (sum < m) {
                    i++;
                    sum = sum + 1.0 / i;

                }
                System.out.println((i - 1) + " card(s)");
            }
        }
    }
}

3.POJ1004

import java.util.Scanner;

/**
 * Created by mxcsky on 2015/1/25.
 */
public class POJ1004 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        double sum = 0.0;
        for (int i = 0; i < 12; i++){
            sum = sum + in.nextDouble();
        }
        System.out.printf("$%.2f", sum/12);
    }
}

 

算法之路——POJ刷题(Java,持续更新中)

标签:

原文地址:http://www.cnblogs.com/mxcsky/p/4249236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!