나는 현재 결과를 보여줄뿐만 아니라 그 결과에 어떻게 도달했는지를 보여주는 계산기가있는 Android 앱을 만들고 있습니까?Java에서 계산의 단계별 계산을 표시하는 방법이 있습니까?
아래 코드의 결과를 단계별로 계산할 수있는 라이브러리 또는 방법이 있습니까?
int a = 5;
int b = 6
int c = 7;
int d = 8;
int result = a + (b * c)/d;
편집 : 나는 수식을 많이 그래서 그런데, 물리학을위한 계산기입니다. exp4j를 사용하여 문자열 수식을 구문으로 구문 분석합니다. 여기에 샘플이 있습니다
//For formula velocity = (finalVelocity - initialVelocity)/time
String formula1 = "(finalVelocity - initialVelocity)/time";
Double result1 = new ExpressionBuilder(formula)
.variables("finalVelocity", "initialVelocity", "time")
.build()
.setVariable("finalVelocity", 4);
.setVariable("initialVelocity", 2);
.setVariable("time", 2)
.evaluate();
//Sample Output
//velocity = (4 - 2)/2
//velocity = 2 /2
//velocity = 1
//For formula finalVelocity = (velocity * time) + initialVelocity
String formula2 = "(velocity * time) + initialVelocity";
Double result12 = new ExpressionBuilder(formula)
.variables("velocity", "time" "initialVelocity")
.build()
.setVariable("velocity", 4);
.setVariable("time", 2)
.setVariable("initialVelocity", 0)
.evaluate();
//Sample Output
//finalVelocity = (4 * 2) + 0
//finalVelocity = 8 + 0
//finalVelocity = 8
많은 수식으로 수식마다 인쇄 단계를 생략하려고합니다. 모든 수식에 대한 단계를 인쇄하는 함수를 갖는 방법을 찾으려고합니다.
int a = 5;
int b = 6;
int c = 7;
int d = 8;
int ans = (b * c);
System.out.println(ans)
ans /= d;
System.out.println(ans)
ans += a;
System.out.println(ans)
이 작업을 수행하려면 먼저 괄호를 검색하여 방정식을 해결하는 기능을 구축 할 수 있습니다 : 당신이 그 문제를 해결하기 위해 BODMAS을 사용하는 것입니다 고려
구체적으로이 결과가 필요합니까, 아니면 산술 계산에 일반이되기를 원하십니까? – Brick
모든 산술 계산 용 –
샘플 입력 및 출력을 추가하십시오. –