Java Arithmetic Operator calculate minutes and seconds

Question

We would like to obtain minutes and remaining seconds from an amount of time in seconds.

For example, 500 seconds contains 8 minutes and 20 seconds.

Read user input from console window

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    // Prompt the user for input
    System.out.print("Enter an integer for seconds: ");
    int seconds = input.nextInt();
 
    //your code here
  }// ww  w. j a v a 2  s .  co m
}


import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    // Prompt the user for input
    System.out.print("Enter an integer for seconds: ");
    int seconds = input.nextInt();
 
    int minutes = seconds / 60; // Find minutes in seconds
    int remainingSeconds = seconds % 60; // Seconds remaining
    System.out.println(seconds + " seconds is " + minutes + 
      " minutes and " + remainingSeconds + " seconds");  
  }
}



PreviousNext

Related