Cześć, wykonuję po kolei zadania z https://pl.spoj.com/ z poziomu łatwe i natrafiłem na zadanie "PP0504D - Reprezentacja liczb typu float", którego nie mogę przejść. Mój kod otrzymuje identyczne wyniki jak są podane w teście a jednak kompilator go nie akceptuje. Czy ktoś byłby mi w stanie powiedzieć czy to jest wina kodu czy muszę jednak dostosować swoje rozwiązanie do kompilator SPOJa, aby to przeszło?
package com.spoj.pl.easy;
import java.util.Scanner;
public class E619 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int numberOfTests = scanner.nextInt();
scanner.nextLine();
for(int i = 1; i <= numberOfTests; i++) {
String numberToTest = scanner.nextLine();
numberToTest = numberToTest.replace(',', '.');
printfloat(Float.valueOf(numberToTest));
}
scanner.close();
}
static void printfloat(float number) {
String hexToShow;
if(number == 0) {
hexToShow = "0 0 0 0";
} else {
int intBits = Float.floatToIntBits(number);
String hexRep = Integer.toHexString(intBits);
StringBuilder builder = new StringBuilder();
for(int i = 0; i < 4; i++) {
String twoBytes = hexRep.substring(2 * i, 2 * i + 2);
if(twoBytes.equals("00"))
builder.append("0");
else
builder.append(twoBytes);
if(i != 3)
builder.append(' ');
}
hexToShow = builder.toString();
}
System.out.println(hexToShow);
}
}