Results 1 to 2 of 2
  1. #1
    TheRocket is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default Arrays & Methods

    Ok what I have is the main method where a user inputs how many numbers they want to input in the next section, this works fine and so does inputting the numbers but how do I print the array out and process the array from method to method?

    Code is below

    Java Code:
    import javax.swing.*;
    public class Arrays
    	public static void main(String[] args)
        	String amount = JOptionPane.showInputDialog(
                       "Enter a number");
            int n = Integer.parseInt(amount);
        	int[] numbers = new int [n];
        	for (int i = 0; i < n; i++)
            	System.out.println(i + "\t" + numbers[n]);
        public static int getNumbers(int n)
        	while(n > 0)
        	String inputNumber = JOptionPane.showInputDialog(
                       "Enter a number");
            int number = Integer.parseInt(inputNumber);	
        return n;

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Houston, TX & Flint, MI
    Rep Power


    do int[] numbers; outside your main method. then inside do numbers = new int[n]

    that will make your array accessable throughout the program.

    to print it out write a for loop from 0 to array.length

Similar Threads

  1. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  2. Need help with Arrays
    By dietgal in forum New To Java
    Replies: 21
    Last Post: 10-08-2008, 02:59 PM
  3. Help with Arrays
    By bri1547 in forum New To Java
    Replies: 4
    Last Post: 08-01-2008, 06:12 AM
  4. arrays
    By hasysf in forum New To Java
    Replies: 12
    Last Post: 07-28-2008, 03:38 AM
  5. Help on Arrays...
    By cuellar14 in forum New To Java
    Replies: 4
    Last Post: 07-25-2008, 09:16 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