1) Public class Main {
Public static void main(String[] args) {
Int[] numbers = {1, 2, 3, 4, 5};
System.out.println(Arrays.toString(numbers));
O/P:
[1, 2, 3, 4, 5]
Reason: Arrays.toString(numbers) converts the array to a string
representation for easy printing.
2) Public class Main {
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]);
O/P:
Reason:This loop prints each element of the array by iterating through its
indices.
3) Import java.util.Arrays;
Public class Main {
Public static void main(String[] args) {
Int[] numbers = {1, 2, 3, 4, 5};
Int start = 0;
Int end = numbers.length – 1;
While (start < end) {
Int temp = numbers[start];
Numbers[start] = numbers[end];
Numbers[end] = temp;
Start++;
End--;
System.out.println(Arrays.toString(numbers));
O/P:
[5, 4, 3, 2, 1]
Reason: This code swaps the elements from the beginning and end of the
array, moving toward the center, thus reversing the array.
4) Public class Main {
Public static void main(String[] args) {
Int[] numbers = {1, 2, 3, 4, 5};
Int max = numbers[0];
For (int number : numbers) {
If (number > max) {
Max = number;
System.out.println(“Max value: “ + max);
O/P:
Max value: 5
Reason:The loop checks each element and updates the `max` variable if
the current element is greater.
5) Public class Main {
Public static void main(String[] args) {
Int[] numbers = {1, 2, 3, 4, 5};
Int valueToFind = 3;
Boolean found = false;
For (int number : numbers) {
If (number == valueToFind) {
Found = true;
Break;
System.out.println(“Value found: “ + found);
O/P:
Value found: true
Reason: The loop searches for the specified value and sets `found` to
`true` if it is present in the array.