package javaapplication5;
import javax.swing.JOptionPane;
public class JavaApplication5 {
public static void main(String[] args) {
// String answer = JOptionPane.showInputDialog(null, "What is the S(n)? If you do not need, input 0");
// double x = Double.parseDouble(answer);
// System.out.println("Your S(n) is :" + x);
double x;
String answer1 = JOptionPane.showInputDialog(null, "What is the first term of your Sigma expression or series?");
double y = Double.parseDouble(answer1);
System.out.println("Your a(1) is :" + y);
String answer2 = JOptionPane.showInputDialog(null, "What is the last term of your Sigma expression or series?");
double z = Double.parseDouble(answer2);
System.out.println("Your a(n) is :" + z);
String answer3 = JOptionPane.showInputDialog(null, "What is the total term of numbers in your sequence? If you don't know this, put 0.");
double n = Double.parseDouble(answer3);
System.out.println("Your n is :" + n);
if(n==0)
{
String answer4 = JOptionPane.showInputDialog(null, "What is the increment of your numbers? How much is it being increased, divided or multiplied by?");
double i = Double.parseDouble(answer4);
System.out.println("Your i is: " + i);
double nn = Math.round(n*100.0)/100.0;
nn = (((z - y)/i) + 1);
System.out.println("Your n is :" + nn);
x = (((y+z)/2) * nn );
System.out.println("The sum of your numbers is: " + x);
}
x = (((y+z)/2) * n );
System.out.println("The sum of your numbers is: " + x);
}
}
Above is a program that is used for calculating the arithmetic series of a Sigma expression, if I'm saying it right. My question is that when the program prompts me for a variable, it will work for positive numbers, but not for negative. Do I have to label a type of variable? Must it be entered in a different manner? Any questions on the code I'll answer.