首页 > 代码库 > 时钟,泳池
时钟,泳池
/** * 时钟 * */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); }
时钟,泳池
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。