Common Loop Errors
Common Loop Errors
Infinite Loops
Infinite loops occur when a loop keeps running indefinitely
Off-by-One Errors
Off-by-one errors are a common type of loop error where the loop iterates one time more or less than desired,
causing incorrect results
2.ARRAYS IN JAVA
Definition
An array is a collection of similar data types stored in contiguous memory locations. Arrays have a fixed
size.
DECLARING , INITIALIZING AND ACCESSING AN ARRAY
Arrays are used to store multiple values in a single variable, instead of declaring
separate variables for each value.
1.To declare an array, define the variable type with square brackets:
String[] cars;
System.out.println(cars[0]);
// Outputs Volvo
public class Main {
public static void main(String[] args) {
// Declaring and initializing an array
int[] numbers = {10, 20, 30, 40, 50};