How Can I Multiply Two Arrays Like int[] * int[] in Java?

prenses_mahmut

I want to multiply two arrays in java. Is there any function for that or how can I do that?

int[] a = new int[]{1,2,3};
int[] b = new int[]{1,2,3};
int[] c = a * b; ?

I researched a bit but could not find.

Locke

There is no built in functionality for this. However, it can be done manually, using streams, libraries, or a number of other approaches.

The easiest and most straightforward approach is to use a for loop.

static int[] arrayMultiply(int[] a, int[] b) {
    int newLength = Math.min(a.length, b.length);
    int[] c = new int[newLength];

    for (int index = 0; index < newLength; index++) {
        c[index] = a[index] * b[index];
    }

    return c;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I multiply two arrays in Ruby?

How can I concat two dynamic int-arrays in C?

How can I multiply corresponding values of two 1-dimensional arrays in Java?

How can I multiply items in two arrays if there are zeros in python?

Can I multiply an int with a boolean in C++?

How can I multiply column of the int numpy array to the float digit and stays in int?

I can't multiply two fields. Error: invalid literal for int() with base 10:

Java: how to compare two int[] arrays for non duplicate elements?

How can I cast a Long to an int in Java?

How can I convert a char to int in Java?

How can I format int numbers in java?

How can I convert a text file into a list of int arrays

How to compare int arrays in Java?

How can I multiplicate two arrays in a way that the first value of arrayA multiply the last value of arrayB?

How can I multiply two arrays with same length and return a new array with these values?

How do I make a method like int.getRed() in java?

How to multiply two integers using two classes, Class one contains method int calculateMultiplication (int, int) and two contains main method?

Concatenating two int arrays

In Kotlin How Can I Convert an Int? to an Int

how to multiply label data with an Int?

Java = How to Remove duplicates in int array without using collections or methods like Arrays.copyOf()?

How do I convert an Int to an Int[] in java?

How can I append two array elements (int) into one array element (int)?

How Arrays.asList(int[]) can return List<int[]>?

In Java, how can I combine two JSON arrays of objects?

How can I concatenate two float arrays in Java?

[[Int]] -> [Int] with multiply

How can I increase an int value from a method in Java

How can I mask a hexadecimal int using Java?