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.showInputDialo g("Enter an integer: ");
array1[i] = Integer.parseInt(tempHolde r);
}
String outputString = "";
for( int i = 0; i < array1[i].length; i++ )
{
outputString = outputString + "Index " + i;
outputString += " contains value: " + array1[i] + "\n";
}
JOptionPane.showMessageDia log ( null, outputString);
System.exit(0);
}
}
//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.showInputDialo
array1[i] = Integer.parseInt(tempHolde
}
String outputString = "";
for( int i = 0; i < array1[i].length; i++ )
{
outputString = outputString + "Index " + i;
outputString += " contains value: " + array1[i] + "\n";
}
JOptionPane.showMessageDia
System.exit(0);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
> I believe Object.Array is defined in Java.
Not defined. please please do *not* to post comments if you are not sure.
Not defined. please please do *not* to post comments if you are not sure.
How about: java.lang.reflect.Array
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html
Mark
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html
Mark
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
should be
for (int i = 0; i < array1.length; i++) {