Java &引用;无法解析符号“;我声明的变量的名称?

Java &引用;无法解析符号“;我声明的变量的名称?,java,arrays,variables,Java,Arrays,Variables,我的问题的解决方案可能是非常明显的,但我还没有找到它。如果您想知道这段代码应该做什么,那么假设您需要10个用户输入的数字,将它们相加,然后输出平均值。到目前为止,我唯一的错误是我的double average=sum/10 它不读取变量sum,我完全不知道为什么 import java.io.*; class Average { public static void main (String args[]) throws IOException { // decl

我的问题的解决方案可能是非常明显的,但我还没有找到它。如果您想知道这段代码应该做什么,那么假设您需要10个用户输入的数字,将它们相加,然后输出平均值。到目前为止,我唯一的错误是我的
double average=sum/10
它不读取变量
sum
,我完全不知道为什么

import java.io.*;
class Average
{
    public static void main (String args[]) throws IOException
    {
        // declare some variables
        int count = 0;
        String inInput;


        // declare array constructer
        double[] userInput = new double[9];

        // declare a reader
        InputStreamReader inStream = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(inStream);


        // print out the array
        while (count >= 9)
        {
            if (count != 10)
            { 
                System.out.println ("Please enter a value");
            }
            else
            {
                System.out.println ("Please enter another value");
            }
            inInput = reader.readLine();
            double inInputDouble = Double.parseDouble(inInput);
            userInput[count] = inInputDouble;
            double sum = sum + userInput[count];
            count++;
        }
        double average = sum / 10;
        System.out.println ("The average of all the numbers you have entered is" + average);
    }
}

如上所述,必须在for循环之前声明sum。 作用域就像程序中的括号

int a ..
{
   int b ...
   {
       int c ...
   }
}
如果所评估的指令与
a
联机,则它无法知道
b
c
的状态,因为它们尚未声明

如果指令指针使用int
c
对行求值,则它知道所有变量,因为它已进入第三级作用域。但是由于
c
是在第三级声明的,在指令指针从括号中移出后,如果未将
c
的值保存在较高级别的变量中,则该值会丢失,因为
c
会被清除,并且不可访问(外部范围)。这与您希望从另一个文件中读取变量相同。。。你不能,作用域就像是从外部开始的便笺,附加新的较小的便笺,在iot使用后,它们会被移除

scope:  class definitions >   method definitions         >       block definitions(for, while, if)
      visible everywhere  -   visible under the method    >   visible in the block only  
                              after it exits method all          (eg: for (int i;..)
                              is gone                            i is not visible outer the  for                       /                                                                     brackets
另一个bug:

newdouble[9]?
你说要花10分。。。

在初始化时,您不计算0。。。0用于基于0的索引(
a[0],a[1],a[2]
需要
新的int[3]
)。。。将其设置为新的双精度[10]

如上所述,必须在for循环之前声明sum。 作用域就像程序中的括号

int a ..
{
   int b ...
   {
       int c ...
   }
}
如果所评估的指令与
a
联机,则它无法知道
b
c
的状态,因为它们尚未声明

如果指令指针使用int
c
对行求值,则它知道所有变量,因为它已进入第三级作用域。但是由于
c
是在第三级声明的,在指令指针从括号中移出后,如果未将
c
的值保存在较高级别的变量中,则该值会丢失,因为
c
会被清除,并且不可访问(外部范围)。这与您希望从另一个文件中读取变量相同。。。你不能,作用域就像是从外部开始的便笺,附加新的较小的便笺,在iot使用后,它们会被移除

scope:  class definitions >   method definitions         >       block definitions(for, while, if)
      visible everywhere  -   visible under the method    >   visible in the block only  
                              after it exits method all          (eg: for (int i;..)
                              is gone                            i is not visible outer the  for                       /                                                                     brackets
另一个bug:

newdouble[9]?
你说要花10分。。。

在初始化时,您不计算0。。。0用于基于0的索引(
a[0],a[1],a[2]
需要
新的int[3]
)。。。将其设置为新的双精度[10]

如上所述,必须在for循环之前声明sum。 作用域就像程序中的括号

int a ..
{
   int b ...
   {
       int c ...
   }
}
如果所评估的指令与
a
联机,则它无法知道
b
c
的状态,因为它们尚未声明

如果指令指针使用int
c
对行求值,则它知道所有变量,因为它已进入第三级作用域。但是由于
c
是在第三级声明的,在指令指针从括号中移出后,如果未将
c
的值保存在较高级别的变量中,则该值会丢失,因为
c
会被清除,并且不可访问(外部范围)。这与您希望从另一个文件中读取变量相同。。。你不能,作用域就像是从外部开始的便笺,附加新的较小的便笺,在iot使用后,它们会被移除

scope:  class definitions >   method definitions         >       block definitions(for, while, if)
      visible everywhere  -   visible under the method    >   visible in the block only  
                              after it exits method all          (eg: for (int i;..)
                              is gone                            i is not visible outer the  for                       /                                                                     brackets
另一个bug:

newdouble[9]?
你说要花10分。。。

在初始化时,您不计算0。。。0用于基于0的索引(
a[0],a[1],a[2]
需要
新的int[3]
)。。。将其设置为新的双精度[10]

如上所述,必须在for循环之前声明sum。 作用域就像程序中的括号

int a ..
{
   int b ...
   {
       int c ...
   }
}
如果所评估的指令与
a
联机,则它无法知道
b
c
的状态,因为它们尚未声明

如果指令指针使用int
c
对行求值,则它知道所有变量,因为它已进入第三级作用域。但是由于
c
是在第三级声明的,在指令指针从括号中移出后,如果未将
c
的值保存在较高级别的变量中,则该值会丢失,因为
c
会被清除,并且不可访问(外部范围)。这与您希望从另一个文件中读取变量相同。。。你不能,作用域就像是从外部开始的便笺,附加新的较小的便笺,在iot使用后,它们会被移除

scope:  class definitions >   method definitions         >       block definitions(for, while, if)
      visible everywhere  -   visible under the method    >   visible in the block only  
                              after it exits method all          (eg: for (int i;..)
                              is gone                            i is not visible outer the  for                       /                                                                     brackets
另一个bug:

newdouble[9]?
你说要花10分。。。

在初始化时,您不计算0。。。0用于基于0的索引(
a[0],a[1],a[2]
需要
新的int[3]
)。。。将其设置为新的双精度[10]

int count始终为0,因此它永远不会进入while(count>=9),当调用sum时,它根本不会被定义,更改while(countint count始终为0,因此它永远不会进入while(count>=9),当调用sum时,它根本不会被定义,更改while(countint count始终为0,因此它永远不会进入while)(count>=9)当sum被调用时,它根本不会被定义,在while中更改它(countint count总是0,所以它永远不会进入while(count>=9),当sum被调用时,它根本不会被定义,在while
循环块中更改它(count您正在声明变量
sum
。一旦该块