Results 1 to 3 of 3
  1. #1
    aconti is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default list all EU contries in one if statement

    Hi please see below: How can I add all countries in the first if statement ?

    Java Code:
    import javax.swing.JOptionPane;
    
    public class box {
    	public static void main(String args[]){
    		
    		String i = JOptionPane.showInputDialog("Please insert your country name");
    		
    		//JOptionPane.showMessageDialog(null, i);
    		
    		if (i == "Germany" || "Italy" || France){
    			JOptionPane.showMessageDialog(null, i + " is in the EU");
    		}else{
    			JOptionPane.showMessageDialog(null, i + " is not in the EU");
    		}
    		
    		
    	}
    
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    First off, compare Strings using equals(), not ==.
    Second, you need to compare all of them like:
    Java Code:
    if (i.equals("Germany") || i.equals("France") etc etc)
    Finally, you could create a collection of some sort (Set<String> maybe) that contains all the country names you want to use and do a contains() on it.

  3. #3
    aconti is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

Similar Threads

  1. Replies: 8
    Last Post: 11-04-2011, 08:30 PM
  2. Replies: 2
    Last Post: 11-22-2009, 05:24 PM
  3. Replies: 3
    Last Post: 11-21-2009, 05:48 PM
  4. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •