1 / 10

JAVA BASICS II

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. */

dorjan
Download Presentation

JAVA BASICS II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA BASICS II

  2. EXPRESSIONS

  3. MORE EXPRESSIONS

  4. 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("-----------------------------"); } }

  5. C:\heinz\examples\TestInit>java DisplayWarning ----------------------------- | | | W A R N I N G | | Possible virus detected | | Reboot and run virus | | remover software | | | -----------------------------

  6. /* 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("============================");

  7. // 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); } }

  8. 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

  9. 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)); } } }

  10. 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

More Related