Link to home
Start Free TrialLog in
Avatar of lusius188
lusius188

asked on

Im working on a simple array that takes 3 values then prints the values and sums them ,but I keep getting this int cannot be dereferenced error

/****************************************************************/
//Program:Array.java
//Date:8/06/03
//
//This program demonstrates the use of arrays in storing data.
//The student will enter and process data according to the
//exercises.
/****************************************************************/

import javax.swing.JOptionPane;

public class Array{

      public static void main ( String args[] ){
      
            final int SIZE = 3;                        //The size of our array
            int array1[] = new int[SIZE];      //Array declaration
      
            String tempHolder;                        // temporary holder for String input
            
            //Prompt to enter 'SIZE' number of integers
      for( int i = 0; i < SIZE; i++ )
{
            tempHolder = JOptionPane.showInputDialog("Enter an integer: ");
            array1[i] = Integer.parseInt(tempHolder);
}

String outputString = "";

      for( int i = 0; i < array1[i].length; i++ )
{
            outputString = outputString + "Index " + i;
            outputString += " contains value: " + array1[i] + "\n";
}
JOptionPane.showMessageDialog ( null, outputString);
      

            System.exit(0);
      }
}
Avatar of Ajay-Singh
Ajay-Singh

> for( int i = 0; i < array1[i].length; i++ )
should be


for (int i = 0; i < array1.length; i++) {
ASKER CERTIFIED SOLUTION
Avatar of ADSLMark
ADSLMark

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would change the name Array to myArray or something else.

I believe Object.Array is defined in Java.
> I believe Object.Array is defined in Java.

Not defined. please please do *not* to post comments if you are not sure.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial