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
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.
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
What have you tried?
Post your current code and any questions about it.
i don't know how to implement it
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.
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
Code :
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