import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
MyVector a = new MyVector();
MyVector b = new MyVector(x, y, z);
MyVector xx = a.add(b);
xx.display();
MyVector yy = a.sub(b);
yy.display();
MyVector zz = a.cross(b);
zz.display();
int dd = a.dot(b);
System.out.println(dd);
in.close();
}
}
class MyVector{
private static int x;
private static int y;
private static int z;
public MyVector(int x, int y, int z) {
this.x=x;
this.y=y;
this.z=z; }
public MyVector() {
x=0;
y=0;
z=0;
}
public MyVector add(MyVector b) {
int xx=this.x+MyVector.x;
i
}
}
如有帮助,望采纳
import java.util.Scanner;
class Main {
public static void main(String[] args) {
System.out.println(0-1);
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
MyVector b = new MyVector(x, y, z);
MyVector a1= new MyVector();
MyVector xx = a1.add(b);
System.out.print("jia");
xx.display();
MyVector a2= new MyVector();
MyVector yy = a2.sub(b);
System.out.print("sub");
yy.display();
MyVector a3= new MyVector();
MyVector zz = a3.cross(b);
System.out.print("cross");
zz.display();
MyVector a4= new MyVector();
int dd = a4.dot(b);
System.out.println(dd);
in.close();
}
}
class MyVector{
private int x;
private int y;
private int z;
public MyVector(int x, int y, int z) {
this.x=x;
this.y=y;
this.z=z; }
public MyVector() {
this.x=0;
this.y=0;
this.z=0;
}
public MyVector add(MyVector b) {
this.x+=b.x ;
this.y+=b.y ;
this.z+=b.z ;
return this;
}
public MyVector sub(MyVector b) {
this.x=this.x-b.x ;
this.y=this.y-b.y ;
this.z=this.z-b.z ;
return this;
}
public MyVector cross(MyVector b) {
this.x*=b.x ;
this.y*=b.y ;
this.z*=b.z ;
return this;
}
public int dot(MyVector b) {
int dot=b.x*this.x+this.y*b.x+b.z*this.z;
return dot;
}
void display(){
System.out.println("("+this.x+","+this.y+","+this.z+")"); ;
}
@Override
public String toString() {
return "MyVector{" +
"x=" + x +
", y=" + y +
", z=" + z +
'}';
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
//(0,0,0)
MyVector v1 = new MyVector();
//(x,y,z)
MyVector v2 = new MyVector(x, y, z);
//加法
v1.add(v2).display();
//减法
v1.sub(v2).display();
//叉乘
v1.cross(v2).display();
//点乘
System.out.println(v1.dot(v2));
}
}
class MyVector {
private final int x;
private final int y;
private final int z;
//无参构造方法
public MyVector() {
this.x = 0;
this.y = 0;
this.z = 0;
}
//有参构造方法
public MyVector(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
//展示坐标
public void display() {
System.out.println("(" + x + "," + y + "," + z + ")");
}
//加法
public MyVector add(MyVector myVector) {
int x = this.x + myVector.x;
int y = this.y + myVector.y;
int z = this.z + myVector.z;
return new MyVector(x, y, z);
}
//减法
public MyVector sub(MyVector myVector) {
int x = this.x - myVector.x;
int y = this.y - myVector.y;
int z = this.z - myVector.z;
return new MyVector(x, y, z);
}
//叉乘
public MyVector cross(MyVector myVector) {
int x = this.y * myVector.z - myVector.y * this.z;
int y = myVector.x * this.z - this.x * myVector.z;
int z = this.x * myVector.y - myVector.x * this.y;
return new MyVector(x, y, z);
}
//点乘
public int dot(MyVector myVector) {
return this.x * myVector.x + this.y * myVector.y + this.z * myVector.z;
}
}