Thursday, April 19, 2012

Selection in JAVA programming language

Java mengguanakan selection to solve the problem of the choice process. In the programming is not all a matter of choice can be done sequentially. Sometimes we come across cases that require a selection process. Selection statement will be useful for such cases. In the java programming language statements, there are two kinds of selection, namely IF and SWITCH. More details will be explained as follows.The first is a selection statement is by using IF. IF statement will have some shape, form the first is IF with a choice. General form as follows.
If (condition)Statements;
Description:• Conditions are used to determine the decision keputasan. If the condition is true then the statement of work• The statement, contains the commands and will be executed if the condition is true.Statements herein may beupa single or multipleThe second form of selection virgin IF statement is IF and ELSE statements. This statement will have two choices, if the condition is true then it is done first and if the statement is false that statement 2 is done. Statements 1 and 2 is a compound statement.

 
If (condition)Statement 1;ElseStatement 2;
Statement is true if else statements are only able to complete the two options. But by making the statement if the berjengjang, then we can manipulate in order to be in use if statements untukmemecahkan problem a lot of options. The statement is the if statement in the if, if in the if statement is often referred to if any. The form:

  
If (condition 1)Statement 1;
         
else if (condition 2)Statement 2;
        
else if (condition 3)Statement 3;
       
else if (kondisi_n)Pernyataan_n;
       
elsePernyataan_x;
This form is useful to resolve any possible act of, the settlement made secar rise.Examples of program.java.until.Scanner import;public class IfNilai{public static void main (String arcgs [])int nil;nil_huruf char = 'E';System.out.print ("Enter number:");masuk.nextInt nil = ();if ((nil> = 0) && (nil <= 20))nil_huruf = 'E';else if ((nil> 20) && (nil <= 40))nil_huruf = 'D';else if ((nil> 40) && (nil <= 60))nil_huruf = 'C';else if ((nil> 60) && (nil <= 80))nil_huruf = 'B';else if ((nil> 80) && (nil <= 100))nil_huruf = 'A';elseSystem.outprintln ("either enter the value");System.out.println ("value of the letter:" + nil_huruf);}}

No comments:

Post a Comment