gpt4 book ai didi

java编译错误: method inside method

转载 作者:行者123 更新时间:2023-11-30 05:38:17 27 4
gpt4 key购买 nike

运行代码时出现以下错误

Line: 18 illegal start of expression

Line: 18 ';' expected

这意味着第 18 行中有代码写得不正确(public boolean Ap(){....}),但我认为它是正确的,我不确定,所以有人可以告诉我出了什么问题

这是部分代码

import java.util.ArrayList;

public class PrimeExample{
public static void main(String args[]){
int i =0;
int m=0;
int flag=0;
int k =10;//number of terms
int d =210;// common difference
int n=2;//it is the number to be checked
m=n/2;
ArrayList list = new ArrayList( );
int number=0;
boolean b= false;
while( Ap() == false){
d++;
list.clear();
public boolean Ap(){}
}
}
}

您可以在这里找到工作代码

http://www.browxy.com/SavedCode/231130

注意:- 我已经删除了部分代码,没有错误,以保护部分代码

最佳答案

问题在于您的 public boolean Ap(){} 方法:

  1. 它应该位于 main 方法之外。
  2. 它应该是静态(因为它是从静态上下文访问的)。
  3. 它应该有一个 return 语句(它必须返回 truefalse)。

关于java编译错误: method inside method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56205255/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com