Results 1 to 5 of 5
  1. #1
    tkas is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Problem with Array and Joptionpane

    Hi all. I am new to Java and I have this problem. I need to create an array with 100 numbers in it. After that a pop up window will prompt the user to import a number from 1 to 100.
    Then another window will inform him that his number is in the X index of the array. So far I have written this:

    Java Code:
    package elearning;
    
    import javax.swing.JOptionPane;
    
    
    public class BigArray {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		String entervalue;
    		int[] array = new int[100]; // create my array
    
    		for (int i = 0; i < array.length; i++){
    			array[i]= i+1; 
    			
    		
    		for (int element : array){		
    			entervalue =  JOptionPane.showInputDialog (null, "give a number from" + array[0] + "to" + array.length);
    			array[i] = Integer.parseInt( entervalue );
    			
    			if (array[i] == element)
    				break;
    		}
    			JOptionPane.showMessageDialog(null, "The number " + array[i] + " is in" +array + " τof array", "Message", JOptionPane.INFORMATION_MESSAGE );
    			System.exit (0);	
    				}
    			}
    }
    Any sugestion pls?
    Last edited by Norm; 11-27-2011 at 10:57 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: Problem with Array and Joptionpane

    Do you have any specific questions or problems with your code?

  3. #3
    tkas is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Problem with Array and Joptionpane

    my code apparently is wrong and I can't find the reason

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default Re: Problem with Array and Joptionpane

    Thanks for letting us know. Do you have a question?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: Problem with Array and Joptionpane

    Describe what the code does, tells us what is wrong with that and describe what you want it to do.

Similar Threads

  1. Problem with Array and Joptionpane
    By tkas in forum New To Java
    Replies: 3
    Last Post: 11-28-2011, 01:12 AM
  2. Replies: 13
    Last Post: 03-20-2010, 01:03 AM
  3. using javax.swing.JOptionPane in array
    By icedragon770 in forum AWT / Swing
    Replies: 12
    Last Post: 11-10-2008, 08:27 AM
  4. JOptionPane problem
    By MomenT in forum New To Java
    Replies: 22
    Last Post: 10-02-2008, 05:56 PM
  5. String array for Choice, JOptionPane doesn't show
    By themburu in forum Java Applets
    Replies: 5
    Last Post: 05-29-2008, 01:10 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
  •