xxxxxxxxxx
// Java Program to Increment All
// Element of an Array by One
public class Increment {
public static void main(String[] args)
{
// assigning values in array
int[] arr = { 50, 25, 32, 12, 6, 10, 100, 150 };
// finding the length of the array
// and assigning it to the variable n
int n = arr.length;
System.out.println(
"******* BEFORE INCREMENT *******");
// printing the elements of array
// before performing operation
for (int i = 0; i < n; i++) {
System.out.print(arr[i]);
System.out.print(" ");
}
// incrementing the values of array
// by 1 with the help of loop
for (int i = 0; i < n; i++) {
arr[i] = arr[i] + 1;
}
System.out.println(" ");
// elements of the array after increment
System.out.println(
"******* AFTER INCREMENT *******");
// printing the elements of array after operation
for (int i = 0; i < n; i++) {
System.out.print(arr[i]);
System.out.print(" ");
}
}
}