As a result of the training material before the material, the following is an example of a simple program example that uses all statements, there is one program help menu, 2 courses seek to know the storage directory and third guessing game program numbers.
Sample JAVA program Making the help menu:
02
public static void main(String args[]) throws java.io.IOException {
char choice;
05
System.out.println(“Help Menu For Syntax:”);
System.out.println(” 1. if”);
06
System.out.println(” 2. switch”);
07
System.out.println(” 3. for”);
08
System.out.println(” 4. while”);
09
System.out.println(” 5. do-while”);
10
System.out.println(” 6. break”);
11
System.out.println(” 7. continuen”);
System.out.print(“Choose one (q for exit): “);
13
choice = (char) System.in.read();
14
} while(choice == ‘n’ | choice == ‘r’);
15
} while( choice < ‘1’ | choice > ‘7’ & choice != ‘q’); if(choice == ‘q’) break;
16
System.out.println(“n”); switch(choice) {
18
System.out.println(“format if:n”);
System.out.println(“if(condition) statement;”);
19
System.out.println(“else statement;”);
22
System.out.println(“format switch:n”);
System.out.println(“switch(expression) {“);
23
System.out.println(” case constant:”);
System.out.println(” statement sequence”);
24
System.out.println(” break;”);
25
System.out.println(” // …”);
26
System.out.println(“}”);
29
System.out.println(“format for:n”);
System.out.print(“for(init; condition; iteration)”);
30
System.out.println(” statement;”);
33
System.out.println(“format while:n”);
System.out.println(“while(condition) statement;”);
36
System.out.println(“format do-while:n”);
System.out.println(“do {“);
System.out.println(” statement;”);
37
System.out.println(“} while (condition);”); break;
39
System.out.println(“format break:n”);
System.out.println(“break; or break label;”); break;
41
System.out.println(“format continue:n”);
System.out.println(“continue; or continue label;”);
coding results, the above example is a java program to select the help menu to see the syntax of the statement that there is
Examples of java program for Displaying Directory Storage Folder program:
02
public class FindFolder{
03
public static void main(String[] args){
05
args = new String[] { “..” };
07
File pathName = new File(args[0]);
String[] fileNames = pathName.list();
08
for (int i = 0; i < fileNames.length; i++){
09
File f = new File(pathName.getPath(), fileNames[i]); if (f.isDirectory()){
10
System.out.println(f.getCanonicalPath());
main(new String[] { f.getPath() });
14
catch (IOException e){
coding results, will feature in the directory where the program that we created is saved
Examples of java program Guess Game Score:
01
import java.io.*; import java.util.*;
02
public class GuessNumber {
03
public static void main(String args[]){ Scanner scan=new Scanner(System.in); BufferedReader reader;
04
Random rand=new Random();
05
System.out.print(“Input limit value of <min max>: “); intmin=scan.nextInt();
06
int max=scan.nextInt(); int acakAngka=0; while(acakAngka<min)
07
acakAngka=rand.nextInt(max); int tebak=-1;
09
reader=new BufferedReader(new InputStreamReader(System.in));
10
System.out.println(“Guess the number between “+min+” to “+max+” !”); boolean invalid=false;
13
System.out.print(“Your guess: “); String line=reader.readLine();
14
if((line==null) || line.equals(“quit”)) break; tebak=Integer.parseInt(line);
16
catch(IOException ioe){} catch(NumberFormatException nfe){
17
System.out.println(“Invalid value (not integer)!”); tebak=-1;
20
if (tebak>=min && tebak <=max){ if (tebak==acakAngka)
21
System.out.println(“Wow, your guess is right The Number : “+jumTebak+” GOOD JOB!”);
22
else if(tebak<acakAngka)
23
System.out.println(“Guess the number is even greater!”);
25
System.out.println(“Guess the number is even smaller!”);
28
System.out.println(“Remember the number between “+min+” to “+max+”!”);
30
}while(tebak!=acakAngka);
the results of coding, example programs inputted guess the numbers between min and max numbers randomly