# Soal latihan java. Soal 1 public class MyClass { public static void main() { int arrmul [] [] = new int [4] [5]; int k = 0; for (int i=0;i<4;i++){ for.

## Presentation on theme: "Soal latihan java. Soal 1 public class MyClass { public static void main() { int arrmul [] [] = new int [4] [5]; int k = 0; for (int i=0;i<4;i++){ for."— Presentation transcript:

Soal latihan java

Soal 1 public class MyClass { public static void main() { int arrmul [] [] = new int [4] [5]; int k = 0; for (int i=0;i<4;i++){ for (int j=0;j<5;j++) { arrmul [i] [j] = k++; } for (int i=0;i<4;i++){ for (int j=0;j<5;j++) { System.out.print(arrmul [i] [j] + " "); } System.out.println(); } }

Soal 2 class TestContinue7 { public static void main(String[] args) { int x=10,y; label1: while(x-->0) { y=0; while(y++<10) { if(y > x) { System.out.println(); continue label1; } System.out.print(x*y + " "); }

Soal 3 public class grade6 { public static void main (String[] arf) { outerLoop: for (int i=0;i<5;i++) { for (int j=0;j<5;j++) { System.out.println("Inside for (j) loop"); if (j==2) continue outerLoop; } System.out.println("Inside for (i) loop"); }

Soal 4 import javax.swing.*; public class bintang { public static void main (String[] args) { int baris; baris=Integer.valueOf(JOptionPane.showInputDialog("Masukkan banyak bintang ?")); for (int i=1;i<=baris;i++) { for (int j=1;j<=baris;j++) { if (i<=j) System.out.print("*"); else System.out.print(" "); } System.out.println(); }

Soal 5 public class MyClass { public static void main() { int x =7; System.out.println("x = "+ x); System.out.println("x >> 2 = " + (x >>2)); System.out.println("x << 2 = " + (x <<2)); System.out.println("x >>> 1 = " + (x >>> 1)); }

Soal 6 class TestIter5 { public static void main(String[] args) { int g,h; System.out.println("Sebelum for"); for(g=0,h=6;g =3;g++,h--) { System.out.println("Nilai g : " + g); System.out.println("Nilai h : " + h); } System.out.println("Setelah for"); }

Soal 7 public class coba2 public static void main (String[] args) { int i,j; for(i=0;i<2;i++) { for(j=0;j<3;j++) { if (i==j) { continue; } System.out.println("i="+i+"j="+j); }

Soal 8 class Operator9{ public static void main(String[] args) { int x,hasil; x = 40; boolean test1 = true; hasil = test1?x/10:x*20; System.out.println("Nilai x : "+ x); System.out.println("Nilai Hasil : "+ hasil); }

Soal 9 class Operator8{ public static void main(String[] args) { int x,y; x=10; y=5; if(x>y & ++x>10) { System.out.println("TRUE 3 x : " + x); System.out.println("TRUE 3 y : " + y); System.out.println("TRUE 3 : "); }else { System.out.println("FALSE 3"); }

Soal 10 class Operator5{ public static void main(String[] args) { int x,y; x = 5; if(x!=0 && (x/2)>=5){ System.out.println("TRUE 1 : " + x); System.out.println("TRUE 1 : "); }else { System.out.println("FALSE 1"); } }

Soal 11 public class sk3 { public static void main (String[] args) { int i=0, j=2; do { i=++i; j--; } while (j>0); System.out.println(i); }

Soal 12 class LitIntFloat { public static void main(String[] args) { int okt1 = 056; int hek1 = 0xc; System.out.println("Nilai Oktal : " + (int) okt1); System.out.println("Nilai Heksa 1 : " + (int) hek1); }

Soal 13 class TestIter8 { public static void main(String[] args) { int a = 0 ; System.out.println("Sebelum while"); while(a>0) { System.out.println("Nilai a : "+a); a--; } System.out.println("Setelah while"); }

Soal 14 class Example { static void main() { int input = Input.readInt(); double real = 20; int i = 0; while ( real > input) { real = real * 0.4; i = i + 1; Output.println(i); }

Soal 15 class TestSwitch3 { public static void main(String[] args) 5 int bulan = 4; switch(bulan) { case 1: System.out.println("pertama"); case 2: System.out.println("kedua"); case 3: System.out.println("kuartal 1"); break; case 4: case 5: System.out.println("kelima"); break; case 6: System.out.println("kuartal 2"); break; case 7: case 8: case 9: System.out.println("kuartal 3"); break; default: System.out.println("kuartal 4"); } System.out.println("keluar dari switch"); }

Soal 16 class TestContinue6 { public static void main(String[] args) { int x=10; System.out.println("Sebelum while"); while(x-->1) { if(x % 2 == 0) continue; System.out.println("Nilai x : " + x); } System.out.println("Sesudah while"); }

Soal 17 class TestSeleksi1 { public static void main(String[] args) { int a,b; a = 10; b = a/2; if(b>5) System.out.println("Pernyataan1 Test Seleksi 1 dieksekusi"); else System.out.println("Pernyataan2 Test Seleksi 1 dieksekusi"); System.out.println("Pernyataan3 Test Seleksi 1 dieksekusi"); }

Download ppt "Soal latihan java. Soal 1 public class MyClass { public static void main() { int arrmul [] [] = new int [4] [5]; int k = 0; for (int i=0;i<4;i++){ for."

Similar presentations