+ 2

How to take user input for complex numbers in Java?

If I give complex number, can I do arithmetic operations on it

30th Jan 2018, 2:47 PM
Sathya
Sathya - avatar
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
30th Jan 2018, 3:36 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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(); } }
30th Jan 2018, 3:28 PM
John Wells
John Wells - avatar