//still having error on calling array in another method and possible problems wi
ID: 3683466 • Letter: #
Question
//still having error on calling array in another method and possible problems with the math language
import java.util.Scanner;
import java.lang.Math;
public class arrayVariance
{
public static void main( String[] args )
{
double[] array = new double[40];
double sumv=0,sumk=0,sum=0,avg=0, xx=0;
double i=0, n=array.length
Scanner in = new Scanner(System.in);
System.out.println("Enter data value, enter -101 to quit. ");
System.out.println("Array size = "+ n);
while(array[i]!=-101 && array.length<40)
//the not equals -101 and less than 40 is correct, already asked for help on this and this got changed to an or statement
{array[i] = in.nextInt();}
for( i = 0; i < array.length; i++ )
{sum = math.Sum(array[i]);}
for( i = 0; i < array.length; i++ )
{avg = sum/array.length;}
for( i = 0; i < array.length; i++ )
{xx =(array[i]-avg);}
for( i = 0; i < array.length; i++ )
{sumv=math.Sum(xx*xx);}
for( i = 0; i < array.length; i++ )
{sumk=math.Sum(xx*xx*xx*xx);}
System.out.println("the data values are:" +array[i]);
}
public static double([],i,sumv,n)
{for( i = 0; i < array.length; i++ )
{double var=sumv/(n-1);
return var;}}
public static double([],i,sumk,n)
{for( i = 0; i < array.length; i++ )
{double kur =sumk/(n*var*var)-3;
return kur;}}
System.out.println("Average= "+avg+", variance= "+var+", kurtosis= "+kur);
}
Explanation / Answer
I think you are new to java programming. There were many errors in your code. You first write sample java programs by refering to a tutorial. you were using unnecessary for loops where they were not required. I think you didn't understand the concept of local variables.
modified code: I just removed Syntactic errors.
import java.util.Scanner;
import java.lang.Math;
public class arrayVariance{
public static void main( String[] args ){
double[] array = new double[40];
double sumv=0,sumk=0,sum=0,avg=0, xx=0;
int i=0, n=array.length;
Scanner in = new Scanner(System.in);
System.out.println("Enter data value, enter -101 to quit. ");
System.out.println("Array size = "+ n);
while(array[i]!=-101 && array.length<40){
array[i] = in.nextInt();
}
for( i = 0; i < array.length; i++ ){
sum = sum+array[i];
}
avg = sum/array.length;
for( i = 0; i < array.length; i++ ){
xx =(array[i]-avg);
sumv=sum+(xx*xx);
}
System.out.println("the data values are:" +array[i]);
}
public static double f(double array[],int i,double sumv,int n){
double var=sumv/(n-1);
return var;
}
public static double g(double array[],int i,double sumk,int n){
double kur=sumk/n-3;
// double kur =sumk/(n*var*var)-3;
return kur;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.