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:
Composition, Aggregation, and Association in Java
Create a Custom Auto-Configuration with Spring Boot
Generating Random Dates in Java
Spring REST API + OAuth2 + Angular
How to Manually Authenticate User with Spring Security
Java Program to Implement Word Wrap Problem
Convert XML to JSON Using Jackson
Giới thiệu Java 8
Spring @RequestMapping New Shortcut Annotations
Java Program to Implement Sorted Singly Linked List
Java Program to Implement HashSet API
Spring Cloud AWS – RDS
Java Program to Implement PriorityBlockingQueue API
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Java Program to Find a Good Feedback Vertex Set
HashMap trong Java hoạt động như thế nào?
Java Program to Implement Merge Sort Algorithm on Linked List
Exploring the Spring 5 WebFlux URL Matching
Java Program to Implement Iterative Deepening
Debug a JavaMail Program
Jackson – Marshall String to JsonNode
Call Methods at Runtime Using Java Reflection
New Features in Java 8
Java Program to Implement EnumMap API
Arrays.asList vs new ArrayList(Arrays.asList())
Java Program to Implement Sparse Matrix
Cơ chế Upcasting và Downcasting trong java
Java 8 and Infinite Streams
Java Program to Implement Ternary Search Tree
Java Program to Check Whether a Directed Graph Contains a Eulerian Cycle
Hướng dẫn Java Design Pattern – Mediator
HttpClient Timeout