Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Application {
- public static void main(String[] args) {
- Vector a = new Vector(13, 25, 4);
- Vector b = new Vector(43, -7, 11);
- ViewResult.showScalarResult(a.scalarProduct(b));
- ViewResult.showVectorResult(a.vectorProduct(b));
- }
- }
- class ViewResult{
- public static void showVectorResult(double[] result) {
- System.out.print("Векторное произведение векторов:[a,b]=<");
- for (int i = 0; i < result.length; i++) {
- System.out.print(result[i] + (i != 2 ? ";" : ">\n"));
- }
- }
- public static void showScalarResult(double d) {
- System.out.println("Скалярное произведение векторов: " + d);
- }
- }
- class Vector {
- private double[] array = new double[3];
- public Vector(double... x) {
- for (int i = 0; i < array.length; i++) {
- array[i] = x[i];
- }
- }
- public double[] vectorProduct(Vector vector) {
- double[] result = new double[3];
- for (int i = 0; i < 3; i++) {
- result[i] = this.array[(i + 1) % 3] * vector.array[(i + 2) % 3] - this.array[(i + 2) % 3] * vector.array[(i + 1) % 3];
- }
- return result;
- }
- public double scalarProduct(Vector vector) {
- double result = 0;
- for (int i = 0; i < 3; i++) {
- result += this.array[i] * vector.array[i];
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement