java 标记“return”语法错误,需要字节

db2dz4w8  于 2023-05-27  发布在  Java
关注(0)|答案(2)|浏览(181)

我正在为学校的一个项目设计代码,在编译以下代码时,我得到的唯一错误代码是标记“return”上的语法错误,需要字节。

static public int getMonthlyTotal(){
  //Calulates utilities
  int monthlyTotal = 0;
  //Define imput streams
  InputStreamReader input = new InputStreamReader(System.in);
  BufferedReader reader = new BufferedReader(input);  

    monthlyTotal = (150 + 60 + 20 + 60 + 800);
}
return monthlyTotal;
ql3eal8s

ql3eal8s1#

static public int getMonthlyTotal(){
  //Calulates utilities
  int monthlyTotal = 0;
  //Define imput streams
  InputStreamReader input = new InputStreamReader(System.in);
  BufferedReader reader = new BufferedReader(input);  

    monthlyTotal = (150 + 60 + 20 + 60 + 800);
    return monthlyTotal;

}
bf1o4zei

bf1o4zei2#

你给出的return语句超出了方法give的作用域,就像这样,它会工作的。

static public int getMonthlyTotal() {
        // Calulates utilities
        int monthlyTotal = 0;
        // Define imput streams
        InputStreamReader input = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(input);

        monthlyTotal = (150 + 60 + 20 + 60 + 800);
        return monthlyTotal;

    }

相关问题