Java Code with Highlight

# Java Code with Highlight

from: http://math.hws.edu/eck/cs124/javanotes3/source/Interest1Console.java show the code :
[java] /* Simulation of console-I/O program Interest1, using ConsoleApplet as a basis. See the file ConsoleApplet.java for more information. David Eck [email protected] */ public class Interest1Console extends ConsoleApplet { protected String getTitle() { return &quot;Sample program \&quot;Interest1\&quot;&quot;; } protected void program() { /* Program computes the amount of interest that is earned on \$17,000 invested at an interest rate of 0.07 for one year. The interest and the value of the investment after one year are printed to standard output. */ double principal; // The value of the investment. double rate; // The annual interest rate. double interest; // Interest earned in one year. /* Do the computations. */ principal = 17000; rate = 0.07; interest = principal * rate; // Compute the interest. principal = principal + interest; // Compute value of investment after one year, with interest. // (Note: The new value replaces the old value of principal.) /* Output the results. */ console.put(&quot;The interest earned is \$&quot;); console.putln(interest); console.put(&quot;The value of the investment after one year is \$&quot;); console.putln(principal); } } [/java]
```Java代码2： [java] public class DateUtil { /** * 只比较日期，不比较小时，分钟，秒 * @param date1 * @param date2 * @return date1 &lt; date2 返回 -1 * date1 = date2 返回 0 * date1 &gt; date2 返回 1 */ public static int compareOnlyDate(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); cal2.set(Calendar.HOUR_OF_DAY, 0); cal2.set(Calendar.MINUTE, 0); cal2.set(Calendar.SECOND, 0); cal2.set(Calendar.MILLISECOND, 0); return cal1.compareTo(cal2); } } [/java]

Rate this post

Related posts:
Java Source Code and Free Java Programming Tutorials
Java Source Code
HTTP code 302
good coders code, great reuse

No tags for this post.
```