码迷,mamicode.com
首页 > 其他好文 > 详细

时钟,泳池

时间:2014-10-20 20:57:10      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   java   for   div   on   log   ad   

/**
 * 时钟
 *
 */
public class Clock {
	private int hour;
	private int minute;
	private int second;

	public Clock() {
		Calendar cal = Calendar.getInstance();
		hour = cal.get(11);
		minute = cal.get(12);
		second = cal.get(13);
	}

	public Clock(int hour, int minute, int second) {
		this.hour = hour;
		this.minute = minute;
		this.second = second;
	}

	public void go() {
		second++;
		if (second == 60) {
			minute++;
			second = 0;
			if (minute == 60) {
				hour++;
				minute = 0;
				if (hour == 24) {
					hour = 0;
				}
			}
		}
	}

	public String showTime() {

		String time = "";
		if (hour < 10) {
			time += "0";
		}
		time += minute + ":";
		if (minute < 10) {
			time += "0";
		}
		time += hour + ":";
		if (second < 10) {
			time += "0";
		}
		time += second;

		return time;
	}
}
//实现
	public static void main(String[] args) throws Exception {
	
		Clock c1 = new Clock(0, 0, 0);
		
		for(;;){
			c1.go();
			System.out.println(c1.showTime());
			Thread.sleep(1000);
		}
	}

 

/**
 * 圆类
 * @author Administrator
 *
 */
public class Round {
	private double r;
	final double P=3.14;
	
	public double perimeter(double r){
		return 2*P*r;
	}
	public double area(double r){
		return P*r*r;
	}
}
//实现
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		Round round = new Round();
		System.out.print("请输入游泳池的半径:");
		double radii=sc.nextDouble();
		
		double brick =(round.area(radii+3)-round.area(radii))*10;
		double wall = round.perimeter(radii+3)*8;
		
		System.out.printf("围墙的造价是 %.0f 元\n地砖的造价是 %.0f 元", wall,brick);
	}

  

时钟,泳池

标签:blog   io   ar   java   for   div   on   log   ad   

原文地址:http://www.cnblogs.com/superyueyue/p/4038452.html

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