Domanda

I am trying to write a java code for UVa 594 "One Little, Two Little, Three Little Endians" .

Long story short: The problem is about taking inputs from the inputstream and converting from little endian to big endian and vice versa. Here is my code:

  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
        }
 }
 }

It works on all the sample inputs given but on submission it showed: Your submission for the problem 594 - One Little, Two Little, Three Little Endians has failed with verdict Runtime error.This means that the execution of your program didn't finish properly. Remember to always terminate your code with the exit code 0.

I think probably throws IOException takes care of the exit code 0.Could anyone help me find the cause for the runtime error.

È stato utile?

Soluzione

To submit a Java solution to UVa you need to always name your class Main and you file Main.java (people always hit upon this problem in UVa).Your code is correct.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top