آرایه ها در جاوا

Array

 

* One Dimension array:

Declaration:

 

Data type   array name[]=new data type name[dimension]

 

Ex:

int test[]=new int [10];

Or

int test[10];// this is usually use in C# and C++ but we can use its in java language too.

 

- Direct assignment:

          int test[]={4,6,8,10};

 

- Accessing array location:

 

for (loop initial variable; variable < number or location; variable ++ )

{

Process: - input

               - processing data

               - output

}

 

---------------------------------------------------------------------------

Example:

 

import javax.swing.JOptionPane;

public class onedimesion

          {

          public static void main(String[]arg)

                   {

                   double d[]=new double[10];

                   String temp;

                   double result;

                   for (int i=0; i<10;i++)

                             {

                             temp=JOptionPane.showInputDialog("Input d");

                             d[i]=double.parsedouble(temp);

                             result=result+d[i];

                             }

                   JOptionPane.showMessageDialog(null,"Result is "+ result);

                   }

          }