2
I have the following code in JAVA:
private int metros = 1500, minutos = 60;
System.out.println("Distância em km = "+(metros/1000));
System.out.println("Tempo em horas = "+(minutoa/60));
However what is displayed after the execution of this is 1km and I wanted it to print on the screen the value formatted ex: "1,5 km" without the need to create a double variable, that is, if possible.
This same problem applies to hours, for example when asked to split 90 min he should return to me 1 and 30 min of the surplus, instead returns me 1 hour.
No converting is no way, 1.5 is a float, if at least one of the operands is not a float or double, its division will never have decimal places, not making use of integer splitting.
– user28595
There are two different problems, it would be interesting to present the part of the code of the second problem too.
– user28595
@diegofm thanks! By the look I will have to create a variable... But as for the formatting of time, I have how to do this?
– lima_t
Do not have to create variable, just have to convert.
– Maniero
A simple solution would be:
System.out.println((minutos/60) + " horas e " + (minutos%60) + " minutos");
– user28595
I believe that the idea of formatting km is similar to the one above. Of course you can use Formatter for better display as well.
– user28595
Thanks, I’ll apply to my problem
– lima_t