Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

increment an array java

/*Java program to increment the elements of an array by one and then print the updated array*/
import java.util.*;  

public class Main  
{  
   public static void main(String args[])   
   {  
       //Define the array and its elements
      int arr[]={10 ,20, 30 ,50, 40 ,60, 70, 89,71};
      
      //Define the length of the array
      int n=arr.length;
      
      //Display the original array
      System.out.println("Initial Array is :");
      for(int i=0;i<n;i++)
      {
          System.out.print(arr[i]+" ");
      }
      System.out.println("");
      
        for(int i=0;i<n;i++)
        {
            arr[i]=arr[i]+1;   //Increment the elements by one
        }
      
       //Display the updated array
      System.out.println("Updated Array is ");    
      for(int i=0;i<n;i++)
      {
          System.out.print(arr[i]+" ");
      }
      System.out.println("");
   }  
}
Comment

PREVIOUS NEXT
Code Example
Java :: remove element from char array java 
Java :: What would be the behavior if this() and super() used in a method? 
Java :: string array to string stream java 
Java :: garbage collection in java 
Java :: flutter doctor Unable to find bundled Java version. 
Java :: list of java 
Java :: java scanner next() 
Java :: change element in array java 
Java :: java switch tutorial 
Java :: string to char array 
Java :: java array quick sort 
Java :: android recyclerview pull to refresh 
Java :: Java Method Create Basic 
Java :: get string size on screen 
Java :: islowercase java 
Java :: android how to know when snackbar is done 
Java :: swagger ui java 
Java :: Java Hasmap Remove Elements 
Java :: singleton 
Java :: dates in java 8 
Java :: java put() method 
Java :: vim yank to clipboard 
Java :: Java How to use NavigableMap? 
Java :: kingkaihockey 
Java :: Java program to swap two numbers using bitwise xor operator 
Java :: rotate vector 3d java 
Java :: What is builder tool 
Java :: XmlRootElement Object to String 
Java :: preparestatement method in java 
Java :: java get current free disc space 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =