Home Java Java-conversion Changing the value of Array in Java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Changing the value of Array in Java

Advertisement
This is very simple of one dimensional array program. In this tutorial you will learn how to change array values. The one dimensional array program is provided Java application program about the explanation with Java Source code.

Changing the Value of Array in Java

     

This is very simple of one dimensional array program. In this tutorial you will learn how to change array values. The one dimensional array program is provided Java application program about the explanation with Java Source code. 

Here we are going to make a program to follows the one dimensional array program. In  this program firstly we are going to define class "ArrayExchange" .Now we have to make a two integer value for array1 and array2. After that in this program we are going to using for loop for array1.length. This program take array type number. We are going to pass array values array2 to array1then display the massage array1 values array2.

Here is the code of this program:

public class CopyArray {
  public static void main(String[] args) {
  int array1[]{2,3,4,5,8,9};
  int array2[] new int[6];
  System.out.println("array:")
  System.out.print("[");
  for (int i=0; i<array1.length; i++){
  System.out.print(" "+array1[i]);
  }
  System.out.print("]");
  System.out.println("\narray1:");
  System.out.print("[");
  for(int j=0; j<array1.length; j++){
  array2[j= array1[j];
  System.out.print(" "+ array2[j]);
  }
  System.out.print("]");
  }
}

Download this Example

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 25, 2008

Ask Questions?    Discuss: Changing the value of Array in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com