Results 1 to 4 of 4
  1. #1
    brmcdani is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default Multiplying Values of an Array

    I am trying to write an application that calculates product of odd integers 1-15 and then let the user determine the range of numbers to multiply after that. Here is what I have so far:

    Java Code:
    public class PartTwo {
    	
    	public static void main (String [] args){
    		
    		int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
    		array[0] = 1;
    		array[2] = 3;
    		array[4] = 5;
    		array[6] = 7;
    		array[8] = 9;
    		array[10] = 11;
    		array[12] = 13;
    		array[14] = 15;
    			
    		
    	}
    }
    Where do I go from here? Thanks

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Ok, first of all, you defined the contents of your array, and then immediately changed them, so rethink that step. And, if all you want to do is calculate the product of a few integers, you would be better off with a loop, a variable for the result, and if you wish to let the user continue with the multiplication after the initial calculation, another variable that stores the last number to be multiplicated.

  3. #3
    brmcdani is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default Reply

    OK please give me an example of what the for loop would look like your talking about. I do not know a damn thing obviously an example would go a long way! Thanks


    Java Code:
    public class PartTwo {
    	
    	public static void main (String [] args){
    		
    		int[] array = { 1, 3, 5, 7, 9, 11, 13, 15};
    		array[0] = 1;
    		array[1] = 3;
    		array[2] = 5;
    		array[3] = 7;
    		array[4] = 9;
    		array[5] = 11;
    		array[6] = 13;
    		array[7] = 15;
    			
    		
    	}
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. An Array of different integer values
    By lithium002 in forum New To Java
    Replies: 7
    Last Post: 12-04-2009, 06:25 AM
  2. Multiplying Variables
    By rnavarro9 in forum New To Java
    Replies: 4
    Last Post: 12-03-2009, 09:10 AM
  3. [SOLVED] Multiplying Objects Problme
    By thelinuxguy in forum Advanced Java
    Replies: 7
    Last Post: 05-07-2009, 06:19 PM
  4. Same values in an array
    By hawaiifiver in forum New To Java
    Replies: 3
    Last Post: 02-24-2009, 09:33 PM
  5. replacing array values
    By Jononomous in forum New To Java
    Replies: 1
    Last Post: 05-22-2008, 04:27 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
  •