-1
I cannot compile my code because the following error appears below:
Exception in thread "main" java.util.Unknownformatconversionexception: Conversion = '0' at java.base/java.util.Formatter.checkText(Formatter.java:2732) at java.base/java.util.Formatter.parse(Formatter.java:2708) at java.base/java.util.Formatter.format(Formatter.java:2655) at java.base/java.io.Printstream.format(Printstream.java:1209) at java.base/java.io.Printstream.printf(Printstream.java:1105) At test/Examples.StandNovablePqDeuRuim.main(Testandonovamentepqdeumau.java:24)
follows the full code:
package Exemplos;
import java.util.Scanner;
public class TestandoNovamentePqDeuRuim {
public static void main(String[] args) {
Scanner leia = new Scanner(System.in);
double tempoDuracao;
double horas;
double minutos;
double segundos;
System.out.println("Digite o tempo de duração do evento em segundos: ");
tempoDuracao = leia.nextDouble();
horas = (tempoDuracao / 3600);
minutos = ((tempoDuracao % 3600) / 60);
segundos = ((tempoDuracao % 3600) % 60);
System.out.printf("Horas: %0.f \nMinutos: %.0f \nSegundos: %.0f", horas,minutos,segundos);
}
}
In
Horas: %0.f, you changed the0and the.place, should beHoras: %.0f- that solves theUnknownFormat– hkotsubo
As for the "Resource Leak", it is probably a Warning (a warning that does not prevent the compilation, otherwise it would not have been able to run the program). It happens because the resource (in this case, the
Scanner) is not being closed. In general, you should close any resource you open, but in that particular case, how it comes to theSystem.in, don’t need to close– hkotsubo