Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Confused with Arrays

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Confused with Arrays

    This is what i have so far...
    import java.util.Scanner;
     
    public class Array
    {
    	private static int getProduct;
     
    	public static void main(String[] args)
    	{
    		int[] array1 = {1, 3, 5};
     
    		System.out.println("Product test: ");
    		System.out.println("input parameters; ");
    		System.out.println("product: ");
     
    	}
    }

    I'm having trouble with arrays and my teacher did a horrible job explaining it. I went and read Java how to program in chapter 7, but it did not help me out that much of understanding it. I'm confused and don't know which array method to use or where to begin on figuring this out.
    getProduct:
    product calculates the product of a series of integers

    Sample Output:

     

    Product test:
    input parameters; 1, 3, 5
    product: 15
    input parameters; 1, 3, 5, 7
    product: 105
    input parameters; 2, 3, 4, 5, 6
    product: 720




  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Confused with Arrays

    Is this program meant to take user input from the console and place the numbers into an array?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Confused with Arrays

    This should help you move forward:

    import java.util.Scanner;
     
    public class Array
    {
        private static int getProduct;
     
        public static void main(String[] args)
        {
        	System.out.println("Product test ");
        	System.out.println("Enter numbers: eg 1,2,3");
     
        	Scanner sc = new Scanner(System.in);
            String numbersStr = sc.nextLine();       
     
            String[] array;
            array = numbersStr.split(",");        
            System.out.print("input parameters: ");
     
            for(int a = 0; a < array.length; a++){
            	System.out.print(array[a] + " ");
            }
     
            //System.out.println("product: ");
     
        }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Confused with Arrays

    getProduct is suppose to to get an unspecified number of integers that is passed to the method using a variable-length argument list, and also returns the product of the integers.

    also thx for putting my method in that code box. How where u able to do that? I'm new to the forums.

Similar Threads

  1. Im so confused! Counting and Summing
    By captiancd89 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 28th, 2010, 06:49 PM
  2. Confused about setting up JSP
    By mjpam in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: September 17th, 2010, 05:14 AM
  3. Ayudame! :confused:
    By wasaki in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 22nd, 2010, 10:37 AM
  4. Replies: 3
    Last Post: February 26th, 2009, 03:04 AM
  5. Confusion with C/C++
    By Eric in forum Java Applets
    Replies: 0
    Last Post: December 22nd, 2008, 02:18 PM