What Is Vector Trap?

Java Code for Vector addition, subtraction and multiplication?

  • Hi, I needed to make a java program in which vectors will be either added, subtracted or multiplied, which the user will choose the method themselves. So far, this is what I've come up with and it has way too many errors. All I want is some suggestions and clues as in which area should I clean up the most. //Vector.java - performing multiplication, division, addition and subtraction import java.util.*; class vector { public static void main (String[] args) { int x, y, z; void read() System.out.println("Please enter number for x: " + x); System.out.println("Please enter number for y: " + y); System.out.println("Print enter number for z: " + z); } // For subtracting vectors { vector c; c.x=x-b.x; c.y=y-b.y; c.z=z-b.z; return c; } // For adding vectors { vector c; c.x=x+b.x; c.y=y+b.y; c.z=z+b.z; return c; } // For multiplying vectors by Scalar product { int prod; vector c; c.x=x*b.x; c.y=y*b.y; c.z=z*b.z; prod=c.x+c.y+c.z; System.out.println("\nScalar Product = " + prod); vector d; d.x=(y*b.z)-(z*b.y); d.y=(x*b.z)-(z*b.x); d.z=(x*b.y)-(y*b.x); return d; } void display() { System.out.println("i" + x + "j" + y + "k" + z); } void main() { vector v1,v2,v3; int choice,cont; do { clrscr(); System.out.println("\nEnter your choice : " + choice); switch(choice) { case 1 : System.out.println("\nEnter the Vector\n"); v1.read(); v3=v1-v2; System.out.println("Negation of the Vector : "); System.out.println("i" + x + "j" + y + "k" + z); break; case 2 :System.out.println("\n\nEnter the First Vector : "); v1.read(); System.out.println("\n\nEnter the Second Vector : "); v2.read(); v3=v1+v2; System.out.println("\n\nThe Sum of Vectors : "); v3.display(); break; case 3 : System.out.println("\n\nEnter the First Vector : "); v1.read(); System.out.println("\n\nEnter the Second Vector : "); v2.read(); v3=v1*v2; System.out.println("\n\nVector Product = "); v3.display(); break; } } }

  • Answer:

    Clean up the input value to avoid the miscalculation of the vectors.... Good luck!

Anne at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Clean up the input value to avoid the miscalculation of the vectors.... Good luck!

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.