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

DeBug

The document contains descriptions of 3 debugging exercises in Java. The first exercise deals with fixing errors in a program that manipulates arrays. The second addresses errors in a program demonstrating object-oriented programming principles with a Car class. The third concerns exception handling and fixing issues in a program with an out-of-bounds array access and division by zero.

Uploaded by

Meme Pur
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)
149 views2 pages

DeBug

The document contains descriptions of 3 debugging exercises in Java. The first exercise deals with fixing errors in a program that manipulates arrays. The second addresses errors in a program demonstrating object-oriented programming principles with a Car class. The third concerns exception handling and fixing issues in a program with an out-of-bounds array access and division by zero.

Uploaded by

Meme Pur
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
You are on page 1/ 2

Debugging Exercise 1: Array Manipulation

Objective: To identify and fix errors in a Java program that manipulates arrays.

public class ArrayManipulation {


public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};

for (int i = 0; i <= numbers.length; i++) {


System.out.println(numbers[i]);
}
}
}

Debugging Exercise 2: Object-Oriented Programming

Objective: To identify and fix errors in a Java program that demonstrates basic
object-oriented programming principles.

class Car {
private String make;
private String model;

public Car(String make, String model) {


this.make = make;
this.model = model;
}

public void start() {


System.out.println("Starting the car.");
}
}

public class Main {


public static void main(String[] args) {
Car car = new Car("Toyota", "Camry");
car.start();
car.stop();
}
}
Debugging Exercise 3: Exception Handling

Objective: To identify and fix errors in a Java program that demonstrates exception
handling.

public class ExceptionHandling {


public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};

try {
System.out.println(numbers[10]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Array index out of bounds.");
}

int result = divide(10, 0);


System.out.println("Result: " + result);
}

public static int divide(int a, int b) {


return a / b;
}
}

You might also like