i'm new in Java and i am trying to make user can get what element from arrays they're asking for.
int[] aksesArray = {30, 50, 10, 90, 70};
So if the user inputs an answer 0, he will get access element 0 which is 30, and so on. And whenever the user inputs 0, 1, 2, 3, 4 the answer will always refer to 30.
i think the problem is on my a = aksesArray.length;
import javax.swing.JOptionPane;
public class pickingArray {
public static void main(String[] args) {
int[] aksesArray = {30, 50, 10, 90, 70};
int inputElm = Integer.parseInt(JOptionPane.showInputDialog("Input Number to find an Element "));
int a = (inputElm);
a = aksesArray.length;
if ( a == aksesArray.length ) {
JOptionPane.showMessageDialog(null, "Element you are looking for : " + aksesArray[0] );
}
else if ( a == aksesArray[1] ) {
JOptionPane.showMessageDialog(null, "Element you are looking for : " + aksesArray[1] );
}
else if ( a == aksesArray.length ) {
JOptionPane.showMessageDialog(null, "Element you are looking for : " + aksesArray[2] );
}
else if ( a == aksesArray.length ) {
JOptionPane.showMessageDialog(null, "Element you are looking for : " + aksesArray[3] );
}
else if ( a == aksesArray.length ) {
JOptionPane.showMessageDialog(null, "Element you are looking for : " + aksesArray[4] );
}
else {
JOptionPane.showMessageDialog(null, "No Element " );
}
}
}
int a=aksesArray[inputElm];