无论我改变什么或尝试做什么,我都无法让我的代码工作。我认为这与 UVA java 提交方式的格式不明确有关。我已经尝试删除所有方法上的“公共”,更改 Main 抛出的异常,更改开始时 while 循环的工作方式,但似乎没有。我还可以做些什么?
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws NumberFormatException, IOException
{
Scanner file = new Scanner(System.in);
while(file.hasNextLine())
{
String line = file.nextLine();
if(line.equals(""))
System.exit(0);
String[] temp = line.split(" ");
int i = Integer.parseInt(temp[0]);
int j = Integer.parseInt(temp[1]);
int cycle = findCycle(i, j);
System.out.println(i + " " + j + " " + cycle);
}
}
public static int findCycle(int i, int j){
int sentNum = i;
int cycles = 0;
while(sentNum <= j){
int n = cycle(sentNum);
if(n > cycles){
cycles = n;
}
sentNum++;
}
return cycles;
}
public static int cycle(int i){
int count = 0;
while(true){
count++;
if(i == 1)
return count;
else if(i % 2 == 1)
i = 3*i + 1;
else
i = i/2;
}
}
}