Для контекста этот код используется для кода научного калькулятора на 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]
Мобильная версия