标签:
计算闰年,根据格里高利历,能被4整除且不能被100整除,或者能被4整除且能被400整除的年份为闰年
/****************************************************************************** * Compilation: javac LeapYear.java * Execution: java LeapYear n * * * % java LeapYear 2004 * true * * % java LeapYear 1900 * false * * % java LeapYear 2000 * true * ******************************************************************************/ public class LeapYear { public static void main(String[] args) { int year = Integer.parseInt(args[0]); boolean isLeapYear; // divisible by 4 isLeapYear = (year % 4 == 0); // divisible by 4 and not 100 isLeapYear = isLeapYear && (year % 100 != 0); // divisible by 4 and not 100 unless divisible by 400 isLeapYear = isLeapYear || (year % 400 == 0); System.out.println(isLeapYear); } }
1元2次方程的求根公式,如果你忘了,自行google吧。
public class Quadratic { public static void main(String[] args) { // TODO Auto-generated method stub double a = Double.parseDouble(args[0]); double b = Double.parseDouble(args[1]); double c = Double.parseDouble(args[2]); double temp = 4.0 * a * c; double discriminant = b*b - temp; double sqroot = Math.sqrt(discriminant); double root1 = (-b + sqroot) / (2.0 * a); double root2 = (-b - sqroot) / (2.0 * a); System.out.println(root1); System.out.println(root2); } }
标签:
原文地址:http://www.cnblogs.com/wukongjiuwoa/p/5671553.html