I'm working on a calculation code that needs to calculate a number between the first input to the final number(second input). When I do it creates this:
What is the first number?
45
What number do you wish to go to?
50
Sum of numbers between 46 and 50 are: 46
Mean is: -1
Median is: 24
Standard Deviation is: NaN
Variance is: 2209
Sum of numbers between 47 and 50 are: 93
Mean is: 0
Median is: 24
Standard Deviation is: 0.0
Variance is: 10858
Sum of numbers between 48 and 50 are: 141
Mean is: 1
Median is: 24
Standard Deviation is: 1.0
Variance is: 30458
Sum of numbers between 49 and 50 are: 190
Mean is: 2
Median is: 24
Standard Deviation is: 1.4142135623730951
Variance is: 65802
Sum of numbers between 50 and 50 are: 240
Mean is: 3
Median is: 24
Standard Deviation is: 1.7320508075688772
Variance is: 121971
Which obviously is not what I want since I want them all together. My code is:
import java.util.Scanner;
public class Statistics {
public static void main(String[] args) {
int number;
int total;
int sum = 0;
int mean;
int median;
double standardDeviation;
int variance=0;
Scanner input = new Scanner(System.in);
System.out.println("What is the first number?");
number = input.nextInt();
System.out.println("What number do you wish to go to?");
total = input.nextInt();
while(total > number){
number++;
sum = sum + (number);
mean= sum/total-1;
if(total%2 == 1){
median=(total+1)/2-1;
}
else{
median=(total/2-1+total/2)/2;
}
variance += Math.pow((sum-mean),2);
standardDeviation= Math.sqrt(mean);
System.out.println(" Sum of numbers between " + number + " and "+ total + " are: " + sum);
System.out.println("Mean is: "+ mean);
System.out.println("Median is: " + median);
System.out.println("Standard Deviation is: " + standardDeviation);
System.out.println("Variance is: " + variance);
}
}
}
I am completely stuck and have been trying for two hours on this one problem. Any advice?