Arrays


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Arrays

  1. #1
    Join Date
    Nov 2002
    Posts
    1

    Unhappy Arrays Help!

    Hello everyone,
    My problem is I need to let the user enter the dimensions of the array at runtime and use loops to fill the array with random number from 50 to 150. I must the random() method.
    Someone please help, I am a beginner! This is what I have so far.

    import java.util.Random;

    public class ArrayTA
    {
    public static void main(String [] args)
    {
    Random random = new Random();

    System.out.print("Enter the length of the row: ");
    int x = SavitchIn.readLineInt();

    System.out.print("Enter the length of the row: ");
    int y = SavitchIn.readLineInt();

    double [][]myDoubles;
    myDoubles = new double [x][y];

    for(int i = 0; i<myDoubles.length; i++){
    for(int j = 0; j<myDoubles.length; j++){
    myDoubles[i][j] = SavitchIn.readLineDouble();}
    System.out.println(myDoubles[i]);
    }

    }
    }

  2. #2
    Join Date
    Nov 2002
    Posts
    59
    I would use a Vector rather than an array...Vectors can be updated dynamically. Check out http://java.sun.com/j2se/1.4.1/docs/...il/Vector.html

    Also don't forget that integers are primitives, and not objects. So to add an integer to a vector, you'd have to use vector.addElement(new Integer(...)) rather than vector.addElement(...)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center