"non-static variable scan cannot be referenced from a static context"
They refer to the three "System.out.println" lines in the code. Any help/explanations would be much appreciated.
import java.util.Scanner;
import java.text.NumberFormat;
public class Assignment2
{
double[] numbers;
int count, negCount = 0;
double minNum, positiveSum = 0;
Scanner scan = new Scanner(System.in);
public static void main (String[] args)
{
while (scan.nextDouble() != 0)
{
numbers[count] = scan.nextDouble();
count++;
}
NumberFormat fmtDollar = NumberFormat.getCurrencyInstance();
System.out.println ("The minimum number is " + Assignment2.findMin(numbers[])); //??????
System.out.println ("The sum of the positive numbers is " + fmtDollar.format(Assignment2.computePositiveSum(numbers[]))); //??????
System.out.println ("The total number of negative numbers is " + Assignment2.countNegative(numbers[])); //??????
}
public static double findMin(double[] numbers, int count) //count is the count of numbers stored in the array
{
int minNum = numbers[0];
for (count = 0; count < numbers.length; count++)
{
if (numbers[count] < minNum)
minNum = numbers[count];
}
return minNum;
}
public static double computePositiveSum(double[] numbers, int count)
{
for (count = 0; count < numbers.length; count++)
{
if (numbers[count] > 0)
positiveSum = positiveSum + numbers[count];
}
return positiveSum;
}
public static int countNegative(double[] numbers, int count)
{
for (count = 0; count < numbers.length; count++)
{
if (numbers[count] < 0)
negCount++;
}
return negCount;
}
}
This post has been edited by ala_heu: 28 January 2010 - 10:07 PM

New Topic/Question
Reply




MultiQuote







|