gpt4 book ai didi

java - 提交时出现编译错误 - UVA

转载 作者:行者123 更新时间:2023-12-01 18:50:26 25 4
gpt4 key购买 nike

我为 UVA-Problem 100 编写此代码并且在 IDE 中运行得很好但在提交时我遇到了这个编译错误:

Main.java:5: class UVA100 is public, should be declared in a file named UVA100.java public class UVA100 { ^ 1 error

我是java编程的新手,我不知道以uva接受的哪种格式发送此代码。

import java.util.Scanner;

public class UVA100 {

public static void main(String[] args) {
int a, b, cnt, MAX, MIN, MaxCycle = 1;

Scanner input = new Scanner(System.in);

while(input.hasNextInt()){

a = input.nextInt();
b = input.nextInt();

MAX = Math.max(a, b);
MIN = Math.min(a, b);

for (int i = MIN; i <= MAX; i++) {
cnt=CalculateCycle(i);
if(cnt>MaxCycle)
MaxCycle=cnt;
}

System.out.print(a + " " + b + " " + MaxCycle);
}
}

public static int CalculateCycle(int n) {
int count = 1;
while (n > 1) {
if (n % 2 == 0) {
n = n / 2;
} else {
n = n * 3 + 1;
}
count++;
}
return count;
}
}

最佳答案

我找到了答案:classes must nor be public in UVa ;-)

Java Specifications: The Java programs submitted must be in a single source code (not .class) file. Nevertheless, you can add as many classes as you need in this file. All the classes in this file must not be within any package.

All programs must begin in a static main method in a Main class.

Do not use public classes: even Main must be non public to avoid compile error.

Use buffered I/O to avoid time limit exceeded due to excesive flushing.

As a reference, we provide a sample Java code

关于java - 提交时出现编译错误 - UVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16057608/

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