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:
So sánh ArrayList và LinkedList trong Java
Java Program to Implement Aho-Corasick Algorithm for String Matching
Vòng lặp for, while, do-while trong Java
Add Multiple Items to an Java ArrayList
Java Program to Find the Nearest Neighbor Using K-D Tree Search
The Spring @Controller and @RestController Annotations
Phân biệt JVM, JRE, JDK
Java Program to Construct an Expression Tree for an Postfix Expression
Java Program to Perform integer Partition for a Specific Case
Composition, Aggregation, and Association in Java
Introduction to Spring Data REST
Intersection of Two Lists in Java
Merging Two Maps with Java 8
Java Program to Represent Linear Equations in Matrix Form
Java Program to Find the Shortest Path from Source Vertex to All Other Vertices in Linear Time
Guide to the Volatile Keyword in Java
Spring Data JPA @Modifying Annotation
Java Program to find the number of occurrences of a given number using Binary Search approach
Spring Webflux with Kotlin
HttpClient Timeout
Spring Boot - Tomcat Port Number
Java Program to Implement Hamiltonian Cycle Algorithm
Configuring a DataSource Programmatically in Spring Boot
Guide to Guava Table
Java Program to Implement Branch and Bound Method to Perform a Combinatorial Search
Tránh lỗi NullPointerException trong Java như thế nào?
Java Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree
Spring Boot Configuration with Jasypt
Java Program to Implement Sorted Array
DistinctBy in the Java Stream API
Java Program to Implement Extended Euclid Algorithm
Spring MVC Setup with Kotlin