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 5 of 5

Thread: Write a program in Java that multiplies the column vector A [n] by some number. The matrix and number are initiated by a random value generator.

  1. #1
    Junior Member
    Join Date
    May 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Write a program in Java that multiplies the column vector A [n] by some number. The matrix and number are initiated by a random value generator.

    Write a program in Java that multiplies the column vector A [n] by
    some number. The matrix and number are initiated by a random value generator.

    --- Update ---

    Please I really need help

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    On vacation
    Posts
    24,756
    Thanks
    57
    Thanked 2,684 Times in 2,634 Posts

    Default Re: Write a program in Java that multiplies the column vector A [n] by some number. The matrix and number are initiated by a random value generator.

    What have you tried?
    Post your current code and any questions about it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Write a program in Java that multiplies the column vector A [n] by some number. The matrix and number are initiated by a random value generator.

    Quote Originally Posted by Norm View Post
    What have you tried?
    Post your current code and any questions about it.
    i don't know how to implement it

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    On vacation
    Posts
    24,756
    Thanks
    57
    Thanked 2,684 Times in 2,634 Posts

    Default Re: Write a program in Java that multiplies the column vector A [n] by some number. The matrix and number are initiated by a random value generator.

    First step is to understand what is to be done. Can you describe what steps the program needs to take to solve the problem?
    What does a column vector A [n] look like? What is in it? Does it contain numbers? Are they integers or float?
    Where does some number come from?
    What is The matrix and number ? Where do they come from?
    random value generator. See the Random class for methods that will generate random numbers.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2022
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Write a program in Java that multiplies the column vector A [n] by some number. The matrix and number are initiated by a random value generator.

    This thread is old enough that doing other people's homework no longer applies, so here's my version

    import java.util.Random;
     
    public class Main{ 
      public static void main(String[] args) { 
        Random rng = new Random(); // random number generator
     
        // create a vector with ten random doubles in the range [0..1)
        double vector[] = new double[10];
     
        // load vector with random values
        for( int index = 0; index < vector.length; index++){
          vector[index] = rng.nextDouble();
        }
     
        displayVector(vector);
     
        // random multiplier int in range [0..100)
        int multiplier = rng.nextInt(100);
     
        // multiply vector by scaling factor (multiplier)
        for( int index = 0; index < vector.length; index++){
          vector[index] *= multiplier;
        }
     
        // display results
        System.out.println(
          String.format("scaled by a factor of %s", multiplier)
        );
        displayVector(vector);
     
      } // main
     
      // display vector
      static void displayVector(double[] vector){
        String output = "v[ ";
        for(double thisValue : vector){
          output += String.format("%4.4f ", thisValue);
        }
        System.out.println(output + "]");
      } // displayVector
     
    } // Main

Similar Threads

  1. [SOLVED] Put a random number from one vector to another
    By JohnJohnson123 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: October 6th, 2013, 06:36 PM
  2. Random Number Generator
    By Rugby_Thompson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 5th, 2013, 12:58 AM
  3. Random Number Generator Always gives 0
    By tlckl3m3elmo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 11th, 2012, 03:09 PM
  4. random number generator
    By java3 in forum Loops & Control Statements
    Replies: 4
    Last Post: February 21st, 2011, 12:00 PM
  5. [SOLVED] Random number method implementation
    By big_c in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2009, 01:10 PM

Tags for this Thread