[Go to site: main page, start]

0% found this document useful (0 votes)
5 views2 pages

Beginner Java Debugging Questions

The document contains a series of Java programming debugging questions aimed at beginners. Each question presents a specific error type, including syntax errors, logical errors, infinite loops, array index errors, NullPointerExceptions, division by zero issues, Scanner input problems, missing return statements, constructor name errors, and wrong data type usage. The questions require the reader to identify and correct these errors in the provided code snippets.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Beginner Java Debugging Questions

The document contains a series of Java programming debugging questions aimed at beginners. Each question presents a specific error type, including syntax errors, logical errors, infinite loops, array index errors, NullPointerExceptions, division by zero issues, Scanner input problems, missing return statements, constructor name errors, and wrong data type usage. The questions require the reader to identify and correct these errors in the provided code snippets.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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);
}
}

You might also like