PERCOBAAN 1 : Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! public class TestGreeting{ public static void main(String[] args){ Greeting hello = new Greeting(); hello.greet(); } } class Greeting { public void greet(){ System.out.println("hi"); } } Preview :
PERCOBAAN 2 : Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test1.java public class Test1{ public static void main(String[] args){ System.out.println("What's wrong with this program?"); } } public class TestAnother1{ public static void main(String[] args){ System.out.println("What's wrong with this program?"); } }
Preview :
PEMBETULAN “Test1.java” Ahmad Reza Musthafa
1
public class Test1{ public static void main(String[] args){ System.out.println("What's wrong with this program?"); TestAnother1 tes=new TestAnother1(); tes.main(); } } class TestAnother1{ public static void main(){ System.out.println("What's wrong with this program?"); } }
Preview :
PERCOBAAN 3 Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test2.java public class Testing2{ public static void main(String[] args){ System.out.println("What's wrong with this program?"); } } Preview :
PEMBETULAN “Test2.java” public class Test2{ public static void main(String[] args){ System.out.println("What's wrong with this program?"); } } Preview : Ahmad Reza Musthafa
2
PERCOBAAN 4 Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test3.java public class Test3{ public static void main(String args){ System.out.println("What's wrong with this program?"); } } Preview :
PEMBETULAN “Test3.java” public class Test3{ public static void main(String[] args){ System.out.println("What's wrong with this program?"); } } Preview :
PERCOBAAN 5 : Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test4.java public class Test4{ public void main(String[] args){ System.out.println("What's wrong with this program?"); } } Preview : Ahmad Reza Musthafa
3
PEMBETULAN “Test4.java” public class Test4{ public static void main(String[] args){ System.out.println("What's wrong with this program?"); } } Preview :
PERCOBAAN 6 : Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test5.java public class Test5 { int[] x = new int[ 10 ]; public Test5() { for (int i = 0; i<= 10; i++){ x[i] = i; System.out.println("Isi x ke : " + i + " = " + x[i]); } } public static void main(String[] args) { Test5 test = new Test5(); } } Preview :
Ahmad Reza Musthafa
4
PEMBETULAN “Test5.java” public class Test5 { int[] x = new int[ 11 ]; public Test5() { for (int i = 0; i<= 10; i++){ x[i] = i; System.out.println("Isi x ke : " + i + " = " + x[i]); } } public static void main(String[] args) { Test5 test = new Test5(); } }
Preview :
PERCOBAAN 7 Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test6.java public class Test6 { int[] x = new int[ 10 ]; int val = 20; Ahmad Reza Musthafa
5
public Test6() { for (int i = 0; i< 10; i++){ x[i] = i; float res = val / x[i]; System.out.println("result " + " = " + res); } } public static void main(String[] args) { Test6 test = new Test6(); } } Preview :
PEMBETULAN “Test6.java” public class Test6 { int[] x = new int[ 11 ]; float val = 20; public Test6() { for (int i = 0; i< 10; i++){ x[i] = i; float res = val / x[i]; System.out.println("result " + " = " + res); } } public static void main(String[] args) { Test6 test = new Test6(); } } Preview :
Ahmad Reza Musthafa
6
PERCOBAAN 8 Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test7.java public Test7 { public static void main(String[] args) { System.out.println("Hallo.."); } } Preview :
PEMBETULAN “Test7.java” public class Test7 { public static void main(String[] args) { System.out.println("Hallo.."); } } Preview :
PERCOBAAN 9 Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test8.java Ahmad Reza Musthafa
7
public class Test8 { String name = "Reza"; public void getName(){ return name; } public static void main(String[] args) { Test8 test = new Test8(); System.out.println("Nama saya : " + test.getName()); } } Preview :
PEMBETULAN “Test8.java” public class Test8 { private String name = "Reza"; public String getName(){ return name; } public static void main(String[] args) { Test8 test = new Test8(); System.out.println("Nama saya : " + test.getName()); } } Preview :
PERCOBAAN 10 Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test9.java public class Test9 { String text = "abaaba"; Ahmad Reza Musthafa
8
public void addText(){ if (text.length() >= 6) { text += text; else { text += text.substring(3); } } System.out.println("New Text : " + text); } public static void main(String[] args) { Test9 test = new Test9(); test.addText(); } } Preview :
PEMBETULAN “Test9.java” public class Test9 { String text = "abaaba"; public void addText(){ if (text.length() >= 6) { text += text; } else { text += text.substring(3); }
System.out.println("New Text : " + text); } public static void main(String[] args) { Test9 test = new Test9(); test.addText(); } } Preview :
Ahmad Reza Musthafa
9
PERCOBAAN 11 Ketik program di bawah ini, bila terjadi kasalahan waktu compile dan runtime, betulkan! Nama file : Test10.java public class Test10 { boolean newAcct = true; double deposit = 17.29;
public void check(){ if (newAcct == true) { double balance = 100.0; } if (deposit > 0) { balance += deposit; } System.out.println("Balance = " + balance); } public static void main(String[] args) { Test10 test = new Test10(); test.check(); } } Preview :
PEMBETULAN “Test10.java” public class Test10 { boolean newAcct = true; double deposit = 17.29; double balance; public void check(){ if (newAcct == true) Ahmad Reza Musthafa
10
{ double balance = 100.0; } if (deposit > 0) { balance =+ deposit; } System.out.println("Balance = " + balance); } public static void main(String[] args) { Test10 test = new Test10(); test.check(); } } Preview :
Ahmad Reza Musthafa
11