100 likes | 210 Views
JAVA BASICS II. EXPRESSIONS. MORE EXPRESSIONS. class DisplayWarning { /** * Displaying a warning program by J M Bishop Aug 1996 * ---------------------------- Java 1.1 October 1997 * Illustrates the form of a program and the use of println. */
E N D
class DisplayWarning { /** * Displaying a warning program by J M Bishop Aug 1996 * ---------------------------- Java 1.1 October 1997 * Illustrates the form of a program and the use of println. */ public static void main(String[] args) { System.out.println("-----------------------------"); System.out.println("| |"); System.out.println("| W A R N I N G |"); System.out.println("| Possible virus detected |"); System.out.println("| Reboot and run virus |"); System.out.println("| remover software |"); System.out.println("| |"); System.out.println("-----------------------------"); } }
C:\heinz\examples\TestInit>java DisplayWarning ----------------------------- | | | W A R N I N G | | Possible virus detected | | Reboot and run virus | | remover software | | | -----------------------------
/* Interest Increase Program by J M Bishop Aug 1996 * ------------------------- Java 1.1 Oct 1997 * Calculates the difference in simple interest for two interest * rates for the remainder of the year from a given month. * * Illustrates declarations, assignment, constants, * expressions and printing. */ class InterestIncrease { static final double p = 1000; // in graz static final int m = 4; // for April static final double oldRate = 12.5; // % static final double newRate = 13.00; // % public static void main(String[] args) { // Start with a title System.out.println("SavBank Interest Calculation"); System.out.println("============================");
// perform the preliminary calculation double ptOver100 = p * (12 - m) / 12 / 100; // print out the results System.out.println("Given a change of interest rate from "+ oldRate+"% to "+newRate+"% in month "+m+","); System.out.println("on a principal of G"+p+ " the interest for the rest of the year"); System.out.print("will change by graz and cents: "); System.out.println(ptOver100 * newRate - ptOver100 * oldRate); } }
C:\heinz\examples\TestInit>java InterestIncrease SavBank Interest Calculation ============================ Given a change of interest rate from 12.5% to 13.0% in month 4, on a principal of G1000.0 the interest for the rest of the year will change by graz and cents: 3.3333333333333286
class TemperatureTable { /* Displays a simple table converting Celsius * to Farhenheit for a given range. * * Illustrates using the loop variable * in expressions in the loop */ public static void main(String[] args) { System.out.println("Temperature Conversion Table"); System.out.println("============================"); System.out.println(); System.out.println("C F"); for (int c = 5; c <= 20; c++) { System.out.print(c+"\t"); System.out.println(Math.round(c*9/5 + 32)); } } }
C:\heinz\examples\TestInit>java TemperatureTable Temperature Conversion Table ============================ C F 5 41 6 42 7 44 8 46 9 48 10 50 11 51 12 53 13 55 14 57 15 59 16 60 17 62 18 64 19 66 20 68