Chapter 2 Java Language Overview

xiaoxiao2021-03-06  46

EXAMPLE.JAVA

/ * * This is a simple java program. Call this file "example.java". * / Public class example {// Your Program Begin with a call to main (). Public static void main (String [] args) {system .out.println ("this is simple java program");}}

EXAMPLE2.JAVA

/ * * Here is another short example. Call this file "example.java". * / Public class example {public static void main (string [] args) {int Num; // this declares a variable called num Num = 100; // this Assign Num a value 100 System.out.println ("this is num:" Num); Num = Num * 2; System.out.Print ("The value of num * 2 is:"); system. Out.println (NUM);}}

Ifsample.java

/ * * DemonStrate the if. Call this file "ifsample.java". * / Public class ifsample {public static void main (string [] args) {Int x, y; x = 10; y = 20; if (x < y) System.out.Println ("x is less y"); x = x * 2; if (x == y) System.out.println ("x now Equal to y"); x = x * 2 ; If (x> y) system.out.println ("x now greater thank"); // this won't display anything if (x == y) System.out.println ("you won't see this ");}}

Fortest.java

/ * * DemonStrate the for loop. Call this file "fortest.java". * / Public class fortest {public static void main (String [] args) {int x; for (x = 0; x <10; x = x 1) System.out.println ("this is x:" x);}}

Blocktest.java

转载请注明原文地址:https://www.9cbs.com/read-57760.html

New Post(0)