Results 1 to 3 of 3
  1. #1
    HalfAZN is offline Member
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    32
    Rep Power
    0

    Question Help adding doubles to an array

    How do I store each double that comes out of this loop into an array?

    Java Code:
    public class Perfect
    {
    public static void main(String[]args)
    {
    
    int count=0;
    boolean contin=true;
    for(int n=1;n<10; n++)
    {
    	double Euclid=Math.pow(2,n-1)*(Math.pow(2, n)-1);
    	
    
    }
    
    
    
    }
    
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Help adding doubles to an array

    ??
    yourArray[n] = Euclid; (please follow the naming conventions!)

  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Help adding doubles to an array

    You can probably create an arraylist
    Java Code:
    ArrayList<Double> lol = new ArrayList<Double>();
    for(int n=1;n<10; n++)
    {
        double Euclid=Math.pow(2,n-1)*(Math.pow(2, n)-1);
        lol.add(Euclid); //adding the number in to the array list
    }
    //printing the result
    System.out.println("Numbers:");
    for(int i=0;i<lol.size();i++){
    System.out.println(lol.get(i));
    }
    WARNING I am Russian so it's possible that I wont understand you correctly...

Similar Threads

  1. Replies: 3
    Last Post: 06-18-2012, 09:44 AM
  2. Replies: 1
    Last Post: 04-05-2011, 08:58 PM
  3. Array always adding to 0???
    By Javawizard in forum New To Java
    Replies: 6
    Last Post: 11-13-2010, 11:02 PM
  4. adding to an array
    By mayhewj7 in forum New To Java
    Replies: 14
    Last Post: 02-19-2009, 05:41 AM
  5. Adding numbers in array
    By Shaolin in forum New To Java
    Replies: 1
    Last Post: 11-15-2007, 06:30 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
  •