java arrays
how do you write the code for multipliying 2 double arrays to be in a 3rd double array?
here is my code:
package employeepay;
/**
*
* @author Owner
*/
public class Main
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
double[] values;
values = getArray();
for (double num : values)
System.out.print(num + " ");
double[] values1;
values1 = getArray1();
for (double num : values1)
System.out.print(num + " ");
double[] values2;
values2 = getArray2();
for (double num : values2)
System.out.print(num + " ");
}
/**
getArray method
@return A reference to an array of doubles.
*/
public static double[] getArray()
{
double[] array = { 1.2, 2.3, 4.5, 6.7, 8.9 };
return array;
}
/**
getArray1 method
@return A reference to an array of doubles.
*/
public static double[] getArray1()
{
double[] array1 = { 1.1, 2.2, 3.3, 4.4, 5.5 };
return array1;
}
/**
getArray2 method
@return A reference to an array of doubles.
*/
public static double[] getArray2(double[]array, double[]array1)
{
double[]array2 = (array[index] * array1[index]);
return array2;
}
}
the lines with double asterisks in front and back are the error lines
thank you.
View Answers
November 19, 2010 at 12:59 PM
Hi Friend,
We have modified your code:
public class MultiplyTwoArrays{
public static void main(String[] args) {
double[] values = getArray();
for (double num : values)
System.out.println(num + " ");
System.out.println();
double[] values1 = getArray1();
for (double num : values1)
System.out.println(num + " ");
System.out.println();
double[] values2 = getArray2(values,values1);
for (double num : values2)
System.out.println(num + " ");
}
public static double[] getArray() {
double[] array = { 1, 2, 4, 6, 8 };
return array; }
public static double[] getArray1() {
double[] array1 = { 1, 2, 3, 4, 5 };
return array1;
}
public static double[] getArray2(double[]array, double[]array1) {
double[]array2=new double[array.length] ;
for(int i=0;i<array2.length;i++){
array2[i] = array[i] * array1[i];
}
return array2;
}
}
You can use simple code also:
public class MultiplyTwoArrays{
public static void main(String[] args) {
double[] array1 = { 1.2, 2.3, 4.5, 6.7, 8.9};
double[] array2 = { 1.1, 2.2, 3.3, 4.4, 5.5};
double []array=new double[array1.length];
for(int i=0;i<array.length;i++){
array[i]=array1[i]*array2[i];
}
for(int i=0;i<array.length;i++){
System.out.println(array[i]);
}
}
}
Thanks
Related Tutorials/Questions & Answers:
java arraysjava arrays can i know how can we intilize the three dimentional
arrays in
java? and how can we assign thae values to that array
Advertisements
java arraysjava arrays i need a
java program to store student details like id,name,addr,marks,average,total..using
arrays..input data using scanner class and by using class, object and constructor
Java with ArraysJava with Arrays I was given the assignment to create two parallel
arrays; both of size 50 (declares 50 as a constant) One is an array of strings... and store it in the
arrays. The input for the problem should be provided in a text
java arraysjava arrays how do you write the code for multipliying 2 double
arrays to be in a 3rd double array?
here is my code:
package employeepay;
/**
*
* @author Owner
*/
public class Main
{ADS_TO_REPLACE_1
/**
* @param args
Java ArraysJava Arrays import java.util.ArrayList;
public class try3{
public static void reduce(int[]arr, int len){
for (int i= 0; i<len;i++) {
arr[i]--;
}
len--;
}
public static void main (String[]args){
int
java arraysjava arrays Suppose that you are required to store information about students for the module Data structures
and Algorithms. The information for each student consists of the student�s ID number, surname,
other names
java; arrays - Java Beginnersjava arrays example How can you create a program, by using
arrays and the output would be X. by using char or string.Thank you
intersection of two java arraysintersection of two
java arrays I am trying to figure out how to compare two
arrays and get the intersection and put this into a third array of the correct size. I know how to copy the two
arrays into the third array but am
arrays in java - Java Beginnersarrays in java Hi All,
I have two
arrays. in this two array some name are same. I want to merge those
arrays into single. But while merging I want to delete duplicate entries. How merge those
arrays.
Thanks,
mln15584
Java Arrays Tutorials(). Browse the following code to Learn
Java Arrays in detail...The java.util.Arrays class helps the programmers to manipulating the
arrays. It provides the methods to easily manipulate the
arrays. Methods provided
Arrays in javaArrays in
java
Arrays are the data structure of
java , we use array
where we need contiguous memory allocation. Array stores same type of data
structure... here :
Java
Array Tutorial
Introduction to java arrays Introduction to
java arrays
...
of
Arrays in
Java Programming language. You will learn how the Array class...
arrays. To meet this feature
java
has provided an Array class which abstracts
arraysarrays using
arrays in methods
Java use
arrays in methods
import java.util.*;
class ArrayExample{
public static int getMaxValue(int[] arr){
int maxValue = arr[0];
for(int i=1;i < arr.length;i
java 2d arraysjava 2d arrays Create a program that will:
a) Create the array and populate it with the given values.
9, 8
2, 17
49, 4
13, 119
2, 19
11, 47.... and if i do it manualy it is wrong.
public class
Arrays {
public static void main
reverse arrays in javareverse
arrays in java how do i write a program in array of size n*m where both n and m are greater than 20 such that the 1st element of an array becomes the last and vice verse
reverse arrays in javareverse
arrays in java how do i make a code that can be used to reverse the elements of an array in two dimension such that the last element of an array becomes the first element of the array and the first element of an array
Arrays Arrays Hi I need help with the following exercises.
Exercise 1: Write a
Java application in which the user is prompted for the total number... of all the values as well.
Exercise 2:
Write a
Java application in which you
Iterating java arrays Iterating
java Arrays
arrays can be iterated by the for, for each loop.
array elements can be added to the list and then it can be iterated by the
iterator() method.
Example 1
public class
arrays help - Java Beginnersarrays help Write a program that sorts values.
? The program includes readIntegers() that
o reads the user inputs
o stores them in an array, and
o returns the array
? The program includes easySort() that
o sorts
ArraysArrays I'm new to
java and I need help completing the question below... called Rebel.java;
2.Create two
arrays. One of them must store integer numbers... the numbers in the second array by 3;
7.Print out the contents of both
arrays.
8.Swap
arraysStore a table with students and information (name, ID, password, crypted password, etc) in a multi-dimensional array "stud"
Arrays and Strings:
Store a table with students and information (name, ID, password, crypted password
Arrays - Java BeginnersArrays I have created a multidimensional array(ten by ten number square) using
java and I would like to separate the coumns using the pipe symbol...://www.roseindia.net/
java arrays - Java Beginners];
int num;
Write
Java statements that do the following:
a. Call the method... components of the type int.What is stored in list after the following
Java code
Java Method with arraysJava Method with arrays My assignment is to write a
java method, smallestIndex, that takes as its parameters an int array and its size, and returns the index of the (first occurrence of the) smallest element in the array. Also
Arrays - Java Beginners();
}
}
}
---------------------------------------------
Read for more information.
http://www.roseindia.net/
java Converting java arrays into list are more tutorials of
arrays in
Java:
Java Array Binary Search example
Converting
java arrays into list
Java
Arrays Tutorials
Iterating
java arrays
Array joining
Java ArraysImplement
Java code which takes 2 dimensional integer array as input and prints out heaviest island Implement
Java code which takes 2 dimensional integer array as input and prints out heaviest island
ArraysArrays Write a program in
java(BlueJ) to store the numbers in single dimensional array(S.D.A)into another S.D.A in reverse order of the location
arraysarrays public class Country{
string countryName;
string location;
int population;
double area;
}
a.write a
java statement to create an array of 10 country objects called mycountry using the Country class.
b.Assuming
ARRAYS SORTING - Java Interview QuestionsARRAYS SORTING How To Sort An Array With Out Using Sort Method ?I Want Code? Hi,
Here is the code in
java. You can find both Ascending and Descending order code. Ascending order is commented.
public class
arrays program - Java Interview Questionsarrays program how to write our own array program to find out n'th highest and n'th least i want source code plz replyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy Hi Friend,
Try the following
guys,, need help,, in java programing,, arraysguys,, need help,, in
java programing,, arrays create a program where you will input 10 numbers and arrange it in ascending way using
arrays Introduction to java arrays
Introduction to
java arrays
In this section you will be introduced to the concept
of
Arrays... of
Arrays in
java. Array
is the most widely used data structure in
java. It can
Introduction to Java Arrays
Introduction to
Java Arrays
In this section you will be introduced to the concept
of
Arrays... of
Arrays in
java. Array
is the most widely used data structure in
java. It can
arrays part 2 - Java Beginnersarrays part 2 Question 2: Useful Array Algorithms and Operations (5 marks)
Upgrade the program in Question 1 so that the program includes:
? A static method search() that:
o Has a parameter of integer array and another
Java using arrays - Java BeginnersJava using arrays Write a program to input a possibly integer n(n<=10);followed by n real values into an array a of size n and the program must perform the following:
Display back the values input
Sort the values
merge sorting in arrays - Java Beginnersmerge sorting in arrays Write a program to insert string or characters to an array and apply merge sorting on this array Hi Friend,
Please visit the following link:
http://www.roseindia.net/
java/beginners
Java Arrays Tutorial Java Arrays Tutorial
Learn
Java Arrays from scratch with ease...
download.
Introduction
to
Java Arrays
In this section you
Structure of Java Arrays
Structure of
Java Arrays
Now lets study the structure of
Arrays in
java. Array
is the most widely used data structure in
java. It can contain multiple values
of the same
Introduction to Java Arrays
Introduction to
Java Arrays
In this section you will be introduced to the concept
of
Arrays in
Java Programming language. You will learn how the Array class in
java