Java Program to Compute Cross Product of Two Vectors

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 Interval Tree
Tạo ứng dụng Java RESTful Client không sử dụng 3rd party libraries
JWT – Token-based Authentication trong Jersey 2.x
Java Program to Implement Kosaraju Algorithm
Java Program to Find the Edge Connectivity of a Graph
Setting the Java Version in Maven
Guide to BufferedReader
Quick Guide to Spring MVC with Velocity
Java Program to Implement Coppersmith Freivald’s Algorithm
Spring Cloud AWS – EC2
Java Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected
Hướng dẫn Java Design Pattern – Intercepting Filter
Java Program to Find Transitive Closure of a Graph
Spring Security Authentication Provider
Tìm hiểu về Web Service
Java Program to Implement RenderingHints API
How to Count Duplicate Elements in Arraylist
Java Program to Implement Naor-Reingold Pseudo Random Function
Java Program to Implement Bubble Sort
Java Program to Compute the Area of a Triangle Using Determinants
Template Engines for Spring
Serialize Only Fields that meet a Custom Criteria with Jackson
JUnit 5 for Kotlin Developers
Inheritance and Composition (Is-a vs Has-a relationship) in Java
Java Program to Perform Finite State Automaton based Search
Database Migrations with Flyway
Disable Spring Data Auto Configuration
Introduction to the Java NIO2 File API
Extra Login Fields with Spring Security
Java Program to Implement Attribute API
Java Program to Perform Left Rotation on a Binary Search Tree
Transaction Propagation and Isolation in Spring @Transactional