Beginner Level Java Programming Debugging
Questions
1. Find the syntax error and correct it:
public class Test {
public static void main(String[] args) {
int a = 10
[Link](a);
}
}
2. Identify and fix the logical error:
public class Test {
public static void main(String[] args) {
int num = 5;
if(num = 10) {
[Link]("Number is 10");
}
}
}
3. Debug the infinite loop:
public class Test {
public static void main(String[] args) {
int i = 1;
while(i <= 5);
{
[Link](i);
i++;
}
}
}
4. Find the array index error:
public class Test {
public static void main(String[] args) {
int[] arr = {1,2,3,4,5};
for(int i = 0; i <= [Link]; i++) {
[Link](arr[i]);
}
}
}
5. Identify the NullPointerException issue:
public class Test {
public static void main(String[] args) {
String name = null;
[Link]([Link]());
}
}
6. Fix the division by zero problem:
public class Test {
public static void main(String[] args) {
int a = 10, b = 0;
[Link](a / b);
}
}
7. Debug the Scanner input issue:
import [Link];
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int num = [Link]();
[Link](num);
}
}
8. Find the missing return statement:
public class Test {
static int add(int a, int b) {
int sum = a + b;
}
}
9. Identify the constructor name error:
public class Test {
void Test() {
[Link]("Constructor");
}
}
10. Debug the wrong data type usage:
public class Test {
public static void main(String[] args) {
int num = "100";
[Link](num);
}
}