我正在尝试为UVa 594“一小,二小,三小恶魔”编写一个java代码。
长话短说:问题在于如何从输入流获取输入,并将小endian转换为大端,反之亦然。这是我的代码:
class Little_endians {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int x;
String str;
while((str=br.readLine())!=null){
x=Integer.parseInt(str);
System.out.println(x+" converts to "+Integer.reverseBytes(x));//converting to the other endian just requires to reverse the bytes
}
}
}它适用于提供的所有示例输入,但在提交时它显示:您提交的问题594 -一个小,两个小,三个小端点已经失败的判决运行时error.This意味着您的程序的执行没有正确完成。记住始终使用退出代码0.终止您的代码。
我想可能会抛出IOException来处理退出代码。如果有人能帮我找出运行时错误的原因吗?
发布于 2014-01-27 20:55:41
要向UVa提交解决方案,您需要始终将类命名为主,并提交Main.java (人们总是在UVa中遇到这个问题),.Your代码是正确的。
https://stackoverflow.com/questions/21349111
复制相似问题