JAVA BASICS II EXPRESSIONS MORE EXPRESSIONS class Display

  • Slides: 10
Download presentation
JAVA BASICS II

JAVA BASICS II

EXPRESSIONS

EXPRESSIONS

MORE EXPRESSIONS

MORE EXPRESSIONS

class Display. Warning { /** * Displaying a warning program by J M Bishop

class Display. Warning { /** * 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("| WARNING |"); 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: heinzexamplesTest. Init>java Display. Warning --------------| | | WARNING | | Possible virus detected

C: heinzexamplesTest. Init>java Display. Warning --------------| | | WARNING | | Possible virus detected | Reboot and run virus | remover software | | | ---------------

/* Interest Increase Program by J M Bishop Aug 1996 * ------------Java 1. 1

/* 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 Interest. Increase { static final double p = 1000; // in graz static final int m = 4; // for April static final double old. Rate = 12. 5; // % static final double new. Rate = 13. 00; // % public static void main(String[] args) { // Start with a title System. out. println("Sav. Bank Interest Calculation"); System. out. println("==============");

// perform the preliminary calculation double pt. Over 100 = p * (12 -

// perform the preliminary calculation double pt. Over 100 = p * (12 - m) / 12 / 100; // print out the results System. out. println("Given a change of interest rate from "+ old. Rate+"% to "+new. Rate+"% 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(pt. Over 100 * new. Rate - pt. Over 100 * old. Rate); } }

C: heinzexamplesTest. Init>java Interest. Increase Sav. Bank Interest Calculation ============== Given a change of

C: heinzexamplesTest. Init>java Interest. Increase Sav. Bank Interest Calculation ============== Given a change of interest rate from 12. 5% to 13. 0% in month 4, on a principal of G 1000. 0 the interest for the rest of the year will change by graz and cents: 3. 3333333286

class Temperature. Table { /* Displays a simple table converting Celsius * to Farhenheit

class Temperature. Table { /* 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("C F"); for (int c = 5; c <= 20; c++) { System. out. print(c+"t"); System. out. println(Math. round(c*9/5 + 32)); } } }

C: heinzexamplesTest. Init>java Temperature. Table Temperature Conversion Table ============== C 5 6 7 8

C: heinzexamplesTest. Init>java Temperature. Table Temperature Conversion Table ============== C 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 41 42 44 46 48 50 51 53 55 57 59 60 62 64 66 68