Advertisement
LightProgrammer000

Converter_relogio

Apr 10th, 2020
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package Extra;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class EX_22
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         // Variaveis
  10.         double val, seg, min, hor, dia, mes;
  11.         double ano, dec, sec, mil;
  12.         double rest_min, rest_hor, rest_dia, rest_mes;
  13.         double rest_ano, rest_dec, rest_sec, rest_mil;
  14.        
  15.         // Instanciacao
  16.         Scanner ent = new Scanner(System.in);
  17.        
  18.         // Dados
  19.         System.out.print("\n# Segundos: ");
  20.         val = ent.nextDouble();
  21.  
  22.         dec = val / (3600 * 24 * 365 * 10); // 1 decada = 315360000 seg
  23.         rest_dec = val % (3600 * 24 * 365 * 10);
  24.        
  25.         ano = rest_dec / (3600 * 24 * 365); // 1 ano = 31536000 seg
  26.         rest_ano = rest_dec % (3600 * 24 * 365);
  27.        
  28.         mes = rest_ano / (3600 * 24 * 30);
  29.         rest_mes = rest_ano % (3600 * 24 * 30);
  30.        
  31.         dia = rest_mes / (3600 * 24 );
  32.         rest_dia = rest_mes % (3600 * 24);
  33.        
  34.         hor = rest_dia / 3600;
  35.         rest_hor = rest_dia % 3600;
  36.        
  37.         min = rest_hor / 60;
  38.         rest_min = rest_hor % 60;
  39.        
  40.         seg = rest_min;
  41.        
  42.         relatorio(dec, ano, mes, dia, hor, min, seg);
  43.     }
  44.    
  45.     private static void relatorio(double dec, double ano, double mes, double dia,
  46.                                   double hor, double min, double seg)
  47.     {
  48.         // Apresentacao
  49.         System.out.println("\n------------------------");  
  50.         System.out.println("* Decadas: " + (long) dec);
  51.         System.out.println("* Anos: " + (long) ano);
  52.         System.out.println("* Meses: " + (long) mes);
  53.         System.out.println("* Dias: " + (long) dia);
  54.         System.out.println("* Horas: " + (long) hor);
  55.         System.out.println("* Minutos: " + (long) min);
  56.         System.out.println("* Segundos: " + (long) seg);
  57.         System.out.println("------------------------");
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement