Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Why is this Java class not working?

I'm just groing through a few exercises and I just want to know why this class is not working.

it is saying 'The value of local variable 'average' is not used'

public class Integers {

public static void main(String[] args) {

int count, index, sum, average ; // declare variables

count = 8; // line 1

index = sum = count + 2; // line 2

sum = count + index * 2; // line 3

average = (count + sum + index) / 3; // line 4

}

}

Help Please, I need understanding.

1 Answer

Relevance
  • 9 years ago
    Favorite Answer

    What you are getting is not actually an error, just an information message. It is telling you that you are never using the variable "average" for anything. For example, if you added the line of code "system.out.println("AVG:" + average)" below your code, the message would disappear, as you are now using the variable for something.

Still have questions? Get your answers by asking now.