This is a Java Program to compute cross product of two vectors. In mathematics, the cross product or vector product is a binary operation on two vectors in three-dimensional space. It results in a vector that is perpendicular to both and therefore normal to the plane containing them.
Here is the source code of the Java Program to Compute Cross Product of Two Vectors. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
//This is a java program to find the cross product of two vectors import java.util.Random; public class Cross_Product { public static void main(String args[]) { Random random = new Random(); int u1, u2, u3, v1, v2, v3; u1 = random.nextInt(10); u2 = random.nextInt(10); u3 = random.nextInt(10); v1 = random.nextInt(10); v2 = random.nextInt(10); v3 = random.nextInt(10); int uvi, uvj, uvk; uvi = u2 * v3 - v2 * u3; uvj = v1 * u3 - u1 * v3; uvk = u1 * v2 - v1 * u2; System.out.println("The cross product of the 2 vectors \n u = " + u1 + "i + " + u2 + "j + " + u3 + "k and \n v = " + u1 + "i + " + u2 + "j + " + u3 + "k \n "); System.out.println("u X v : " + uvi + "i +" + uvj + "j+ " + uvk + "k "); } }
Output:
$ javac Cross_Product.java $ java Cross_Product The cross product of the 2 vectors u = 3i + 8j + 9k and v = 3i + 8j + 9k u X v : -2i +48j+ -42k
Related posts:
Java Program to Implement Hash Tables with Linear Probing
Java Program to Implement the Edmond’s Algorithm for Maximum Cardinality Matching
Java Program to Implement Sparse Array
Java Copy Constructor
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Spring Boot - Scheduling
A Guide to Java 9 Modularity
A Guide to TreeMap in Java
Apache Tiles Integration with Spring MVC
Java Program to Implement First Fit Decreasing for 1-D Objects and M Bins
Java Program to Generate All Subsets of a Given Set in the Gray Code Order
Java InputStream to Byte Array and ByteBuffer
Java 8 and Infinite Streams
Getting Started with GraphQL and Spring Boot
A Guide to Java HashMap
Java Program to Implement Merge Sort on n Numbers Without tail-recursion
Control the Session with Spring Security
Spring @RequestParam Annotation
Java Program to Implement the linear congruential generator for Pseudo Random Number Generation
Validate email address exists or not by Java Code
Java Program to implement Sparse Vector
Java IO vs NIO
Java Program to Implement Hash Tables with Quadratic Probing
Pagination and Sorting using Spring Data JPA
Java Program to Find the Nearest Neighbor Using K-D Tree Search
Spring – Injecting Collections
Object Type Casting in Java
Java Program to Search for an Element in a Binary Search Tree
Java Program to Implement HashMap API
Java Program to Implement Coppersmith Freivald’s Algorithm
Jackson Date
Compare Two JSON Objects with Jackson