복소수구하는거좀 도와주세요..
좍좍
소스코드
결과가 안나와요
복소수를 구하는 프로그램을 짜려고하는데요..
덧셈, 곱셈, 뺄셈을 하는데.. 텍스트파일에 입력된 숫자를 읽어와서 출력을 해야되는데
오류는 없는데 결과가 나오지가 않네요..
뭐가 문제인가요??
class complex {
double realpart;
double imaginedpart;
// constructor
public complex(double real, double imagined) {
realpart = real;
imaginedpart = imagined;
}
public string tostring() {
return + realpart + + + imaginedpart + i;
}
public complex add(complex another) {
double r = realpart + imaginedpart;
double i = another.realpart + another.imaginedpart;
complex result_a = new complex(r, i);
return result_a;
}
public complex subtract(complex another) {
double r = realpart - imaginedpart;
double i = another.realpart - another.imaginedpart;
complex result_s = new complex(r, i);
return result_s;
}
public complex multiply(complex another) {
double r = (realpart * imaginedpart) - (another.realpart * another.imaginedpart);
double i = (realpart * another.imaginedpart) + (another.realpart * imaginedpart);
complex result_m = new complex(r, i);
return result_m;
}
}
import java.io.*;
import java.util.scanner;
public class complexmain{
public static void main(string args[]) throws filenotfoundexception {
scanner input = new scanner(new file(input.txt));
while(input.hasnextline()) {
string line = input.nextline();
scanner lineinput = new scanner(line);
string op = lineinput.next();
string chr1 = lineinput.next();
string chi1 = lineinput.next();
string chr2 = lineinput.next();
string chi2 = lineinput.next();
while(lineinput.hasnextline()) {
string opplus = lineinput.next();
double r1p = lineinput.nextdouble();
double i1p = lineinput.nextdouble();
double r2p = lineinput.nextdouble();
double i2p = lineinput.nextdouble();
complex c1p = new complex(r1p, i1p);
complex c2p = new complex(r2p, i2p);
complex result_a = c1p.add(c2p);
system.out.println(add : + result_a.tostring());
}
while(lineinput.hasnextline()) {
string opsub = lineinput.next();
double r1s = lineinput.nextdouble();
double i1s = lineinput.nextdouble();
double r2s = lineinput.nextdouble();
double i2s = lineinput.nextdouble();
complex c1s = new complex(r1s, i1s);
complex c2s = new complex(r2s, i2s);
complex result_s = c1s.subtract(c2s);
system.out.println(subtract : + result_s.tostring());
}
while(lineinput.hasnextline()) {
string opmul = lineinput.next();
double r1m = lineinput.nextdouble();
double i1m = lineinput.nextdouble();
&ndouble r2m = lineinput.nextdouble();
double i2m = lineinput.nextdouble();
complex c1m = new complex(r1m, i1m);
complex c2m = new complex(r2m, i2m);
complex result_s = c1m.multiply(c2m);
system.out.println(subtract : + result_s.tostring());
}
}
}
}
이렇게 짰거든요... 텍스트 파일은 첨부했어요...
텍스트 파일에서 그 라인에 있는 숫자는 해당 계산만 해야되거든요...
도와주세요...
-
블레이
네.
-
물병자리
오류는 안뜨거든요... 그런데 왜 결과값이 출력이 안되는건지 모르겠네요..
제가 text 파일의 값을 계산하려고 하거든요..