Results 1 to 3 of 3
  1. #1
    ryanugsod is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default how to print the index...

    Java Code:
    import javax.swing.*;
    
    public class copyarraydemo{
    	
      public static void main(String[] args){
       
       String[] copyFrom =new String[5] ;
       String[] copyTo =new String[5];
       String a="";
       int n,num=0;
       int index=0;
       		
       		for( n=0; n<4; n++){
      
    			copyFrom[n] = JOptionPane.showInputDialog("Enter A String:");
    			
    			
    			 a= a + copyFrom[n] + "\n";
    			
    			}
    	
       	 JOptionPane.showMessageDialog(null,"Strings: \n"+ a);
       	  
       	  while(num>4 || num<1){
       	 
       	  num=Integer.parseInt(JOptionPane.showInputDialog("Enter Index:"));
       	  
       	  
    
    	
       	
       	 }
    }}
    could anyone help me how to print the index in my code..
    if you enter an invalid index it will prompt outbound exception error...
    Last edited by Eranga; 12-16-2010 at 06:18 PM. Reason: code tags added

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    You mean print the value of num?

    Java Code:
    System.out.println(num);
    PS- Those are code tags. Learn 'em, use 'em, love 'em.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    @op, please use code tags next time when your are posting again in the forum. Unformated codes are really hard to read. If you don't know how to do that, check on my forum signature.

Similar Threads

  1. Redirecting port 80 index to port 8080 index
    By chyrl in forum Advanced Java
    Replies: 0
    Last Post: 11-30-2010, 03:15 PM
  2. Replies: 0
    Last Post: 10-29-2010, 08:15 PM
  3. Index of an int
    By wake in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 01:54 PM
  4. I can't run my index.jsp
    By gissah in forum New To Java
    Replies: 0
    Last Post: 03-23-2009, 01:42 AM
  5. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 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
  •