Skip to content

Instantly share code, notes, and snippets.

@P0huber
Created June 26, 2017 18:39
Show Gist options
  • Save P0huber/16ad13e20419517bb0d08cd17b72a7e4 to your computer and use it in GitHub Desktop.
Save P0huber/16ad13e20419517bb0d08cd17b72a7e4 to your computer and use it in GitHub Desktop.
Расчет остатка секунд последнего часа от введенного значения с проверкой. Calculation of remainder seconds of last hour [Java].
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter any number seconds: ");
int n = s.nextInt(); // entering the any whole number
System.out.println("We have " + getCountSecondsPassedInCurrentHour(n) + " seconds of the last hour."); // call of function with the value
System.out.println("And it`s exactly: " + n / 3600 + " hours and " + n % 3600 + " seconds.");
}
public static int getCountSecondsPassedInCurrentHour(int seconds) {
if (seconds == 3600){// examenation of the condition
return 0;
} else if (seconds < 3600) {
return seconds;
} else {
return seconds % 3600;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment