FOR statement JAVA

FOR statement JAVA

The loop process (Loop: FOR statement)

An iterative process using the statement for the java language you can see the program coding examples below:
01public class GalToLiter{
02public static void main(String args[]) {
03double liter;
04int galon;
05int counter; counter = 0;
06for(galon = 1; galon <= 100; galon++){ liter = galon * 3.7854;
07System.out.println(galon + " galon adalah " + liter + " liter."); counter++;
08if(counter == 10) {
09System.out.println(); counter = 0;
10}
11}
12}
13}

FOR statement JAVA
coding results, will produce results loping of charging each additional gallon, every gallon added the liter will increase up to 100 gallons.


Examples of the other looping coding is dangdingdong following games:
01public class DangDingDong {
02public static void main(String[] args){ for(int = 1; i <= 100; i++) {
03if (((i % 5== 0) && ((i % 7== 0))
04System.out.print("dangdingdong"); else if ((i % 5== 0)
05System.out.print("ding"); else if ((i % 7== 0)
06System.out.print("dong");
07else
08System.out.print(i); System.out.print(" ");
09}
10System.out.println( );
11}
12}

FOR statement JAVA
coding results from this program produces looping to the provisions making the numbers 1 to 100, wherein each multiple of five will bring up the word ding, each multiple of 7 displays the word dong, and if the number of multiples of 5 and 7 simultaneously unite as number 35 will display the dangdingdong.


Examples of coding looping dangdingdong game with Switch:
01public class dangdingdongSwitch {
02public static void main(String[] args) { for(int = 1; i <= 100; i++) {
03switch(i % 35) { case 0:
04System.out.print("DangDingDong "); break;
05case 5:
06case 10:
07case 15:
08case 20:
09case 25:
10case 30:
11System.out.print("Ding "); break;
12case 7:
13case 14:
14case 21:
15case 28:
16System.out.print("Dong "); break;
17default:
18System.out.print(i + " "); break;
19}
20}
21System.out.println( );
22}
23}

FOR statement JAVA
the results of coding, the same as the previous examples in this program differ only in the increments are using a switch case

Berlangganan update artikel terbaru via email:

0 Response to "FOR statement JAVA"

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel