+ 2
How to take user input for complex numbers in Java?
If I give complex number, can I do arithmetic operations on it
2 Respostas
+ 14
u can take input in form of a 2-d array
n rows & 2 columns
//where n is number of complex numbers u want to input
+ 4
You can do it. However, it must be done with functions. Note: not compiled so may have syntax errors. Meant to show method only.
public class complex {
private double real, imaginary;
public void add(complex second) {
this.real += second.real; // could return new instance
this.imaginary += second.imaginary;
}
public void read() {
// assume Scanner scan; is global
this.real = scan.nextDouble();
this.imaginary = scan.nextDouble();
}
}