weixin_42501999 2013-03-10 18:27
浏览 225
已采纳

几个java的error,找来找去也不觉得是个error,error信息我用注释标出来了,共三行

[code="java"]
import java.util.Scanner;
import java.math.*;
public class Main{
final static int MAXN = 10010;
final static int MAXV = 4;
static int[] value = new int [MAXV];
static int[] vol = new int [MAXV];
static int[] dp = new int [MAXN];[color=red]//Syntax error on token ";", { expected after this token[/color]
value[1]=vol[1]=150;
value[2]=vol[2]=200;
value[3]=vol[3]=350;
public static void main(String[] args){[color=red]//Syntax error on token ")", ; expected[/color]
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int t = in.nextInt();
while ((t--) > 0) {
int n = in.nextInt();
for (int i = 0; i <= n; i++) {
dp[i] = 0;
}
for (int i = 1; i <= MAXV-1; i++) {
for (int j = vol[i]; j <= n;j++) {
dp[j] = Math.max(dp[j], dp[j-vol[i]]+value[i]);
}

}
System.out.println(n-dp[n]);
}
}
}
}[color=red]//Syntax error, insert "}" to complete ClassBody[/color]
[/code]

  • 写回答

1条回答 默认 最新

  • weixin_42397707 2013-03-10 19:14
    关注

    value[1]=vol[1]=150;

    value[2]=vol[2]=200;

    value[3]=vol[3]=350;

    这一段赋值放在方法内,或者用一个static块;
    最后多了一个大括号;
    [code="java"]
    import java.util.Scanner;
    import java.math.*;
    public class Main{
    final static int MAXN = 10010;
    final static int MAXV = 4;
    static int[] value = new int [MAXV];
    static int[] vol = new int [MAXV];
    static int[] dp = new int[MAXN];//Syntax error on token ";", { expected after this token[/color]

        public static void main(String[] args){//Syntax error on token ")", ; expected[/color]
            value[1]=vol[1]=150;
            value[2]=vol[2]=200;
            value[3]=vol[3]=350;
            Scanner in = new Scanner(System.in);
            while (in.hasNextInt()) { 
                int t = in.nextInt();
                while ((t--) > 0) {
                    int n = in.nextInt();
                    for (int i = 0; i <= n; i++) {
                        dp[i] = 0;
                    }
                    for (int i = 1; i <= MAXV-1; i++) {
                        for (int j = vol[i]; j <= n;j++) {
                            dp[j] = Math.max(dp[j], dp[j-vol[i]]+value[i]);
                        }                   
                    }
                    System.out.println(n-dp[n]);
                }
            }
        }
    }//Syntax error, insert "}" to complete ClassBody[/color]
    

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器