/* ***************************************** AUTHOR ******************************************** */ import java.util.Arrays; import javax.swing.*; // import the swing library for I/O class painting { public static void main (String[] args) { vote(); System.exit(0); } public static void vote() { String[] paintings = {"Mona Lisa","Water Lilies","The Scream","A Young Rembrandt"}; int[] scores = {0,0,0,0}; String painting; for (int y=0; y<paintings.length; y++) { System.out.println("Vote "+ y + " for " + paintings[y]); } for (int i=0; i<paintings.length; i++) { painting = JOptionPane.showInputDialog("Which painting would you like to vote for?"); System.out.println(Arrays.toString(paintings)); if (paintings[i].equalsIgnoreCase(painting)) { JOptionPane.showMessageDialog(null, "You voted for " + painting); scores[i] = scores[i] + 1; } else if(painting.equals("-33")) { for(int z=0; z<paintings.length; z++) System.out.println((scores[z] + " " + paintings[z])); } else { JOptionPane.showMessageDialog(null, "Invalid Entry"); } } } }
Why does my program skip the IF statement and just goes to the else part and prints "Invalid Entry" even when i enter a correct painting :S