• Post Reply Bookmark Topic Watch Topic
  • New Topic

Math calculations in JAVA  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to convert the length in seconds to the length in minutes and seconds using java math .
For example, 100 seconds = 1 minute, 40 seconds or 1:40.
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,
Welcome to JavaRanch!
Use the division and modulus operators.
If "s" is an integer number of seconds, the n / 60 is the number of minutes, and n % 60 is the number of seconds.
System.out.println((n/60) + ":" + (n%60));
 
Daniel Roman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tanks for the quick answer
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!