+ 2
Can i use a double and restrict the number after the decimal? See example
// the mins go over 59 i want to stop that if possible i know i could do each one individually but wonding if theres a faster way// Scanner scn = new Scanner(System.in); double time = scn.nextDouble(); if(time < 12.00 && time > -1 ){System.out.println(time + " A.M");} else if(time < 24.00 && time > 11.59){System.out.println(time + " PM");} else{System.out.println("Time Unknown");}
2 Réponses
0
use decimal formatter.
0
Yes you can. Instead of using println, you have to use printf, where the f means format. For 2 decimal places, printf("%f.2",time). So if you want three decimal places, make it .3,etc.