
In Java, AN array is a data structure that stores a fixed size collection of elements of the same variable type. Arrays provide a way to store multiple values of the type under a single variable name.
To declare an array in Java, you specify the type of elements the array will hold, followed by square brackets []
and the name of the array variable. Here’s an example of declaring an array of integers:
import java.util.*;
public class Marks {
public static void main(String[] args) {
int[] marks = new int[5];
marks[0] = 55;
marks[1] = 88;
marks[2] = 99;
marks[3] = 77;
marks[4] = 88;
System.out.println(marks[0]);
System.out.println(marks[1]);
System.out.println(marks[2]);
System.out.println(marks[3]);
System.out.println(marks[4]);
}
}
for loop
import java.util.*;
public class Array1 {
public static void main(String[] args) {
int[] marks = new int[3];
marks[0] = 97;
marks[1] = 77;
marks[2] = 33;
for (int i = 0; i < 3; i++) {
System.out.println(marks[i]);
}
}
}
Use of break statement in java program
public class Breaktest{
public static void main(String []args)
{
for (int j = 0; j< 5; j++)
{
if (j == 5)
break;
System.out.println(j);
}
System.out.println("after loops");
}
}
continue STATEMENT IN JAVA
public class continue {
public static void main(String []args)
{
for (int j = 0; j<10; j++)
{
if (j%2!=0)
continue;
//even number is printed
System.out.print(j+"");
}
}
}