2^x и другие тестовые примеры не работают для суммирования.JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 2^x и другие тестовые примеры не работают для суммирования.

Сообщение Anonymous »

В этом коде я должен найти сумму уравнения. x^2 работает, но 2^x, а также, например, 3^y, не работает. Как это исправить, не меняя особых изменений?
Для контекста этот код используется для кода научного калькулятора на Java.

Код: Выделить всё

    if (e.getSource() == summationButton)
{ // summation
try
{
String startInput = JOptionPane.showInputDialog(null, "Enter start value");
String endInput = JOptionPane.showInputDialog(null, "Enter end value");

if (startInput != null && !startInput.isEmpty() && endInput != null && !endInput.isEmpty())
{
int start = Integer.parseInt(startInput);
int end = Integer.parseInt(endInput);

if (start > end)
{
textfield.setText("Error - start value must be equal to the end value.");
return;
}
String expressionInput = JOptionPane.showInputDialog(null, "Enter the expression (polynomial or any math expression):");

if (expressionInput != null && !expressionInput.isEmpty())
{
double summationResult = 0;
for (int x = start; x  end)
{
textfield.setText("Error - start value must be less than or equal to the end value.");
return;
}

String expressionInput = JOptionPane.showInputDialog(null, "Enter the expression (polynomial or any math expression):");

if (expressionInput != null && !expressionInput.isEmpty())
{
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");

expressionInput = expressionInput.replaceAll("\\^", "**");

double summationResult = 0;
for (int x = start; x 

Подробнее здесь: [url]https://stackoverflow.com/questions/79093194/2x-and-other-test-cases-do-not-work-for-summation[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»