Advertisement
Guest User

Untitled

a guest
May 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class coisas {
  4.  
  5.     public static int Ano(int a, int b) {
  6.  
  7.         if (b - 1 == 0) {
  8.             return 0;
  9.         } else if (b - 1 > a) {
  10.             if (b % 400 == 0 | ((b -1) % 4 == 0 && (b-1) % 100 != 0)) {
  11.                 return 366 + Ano(a, b - 1);
  12.             } else {
  13.                 return 365 + Ano(a, b - 1);
  14.             }
  15.         }
  16.         return 0;
  17.  
  18.     }
  19.  
  20.     public static int Mes(int a, int b, int c) {
  21.  
  22.         if (b - 1 == a) {
  23.             return 0;
  24.         } else if (b - 1 == 1) {
  25.             return 31 + Mes(a, b - 1, c);
  26.         } else if (b - 1 == 2) {
  27.             if (c % 400 == 0 | (c % 4 == 0 && c % 100 != 0)) {
  28.                 return 29 + Mes(a, b - 1, c);
  29.             } else {
  30.                 return 28 + Mes(a, b - 1, c);
  31.             }
  32.         } else if (b - 1 == 3) {
  33.             return 31 + Mes(a, b - 1, c);
  34.         } else if (b - 1 == 4) {
  35.             return 30 + Mes(a, b - 1, c);
  36.         } else if (b - 1 == 5) {
  37.             return 31 + Mes(a, b - 1, c);
  38.         } else if (b - 1 == 6) {
  39.             return 30 + Mes(a, b - 1, c);
  40.         } else if (b - 1 == 7) {
  41.             return 31 + Mes(a, b - 1, c);
  42.         } else if (b - 1 == 8) {
  43.             return 31 + Mes(a, b - 1, c);
  44.         } else if (b - 1 == 9) {
  45.             return 30 + Mes(a, b - 1, c);
  46.         } else if (b - 1 == 10) {
  47.             return 31 + Mes(a, b - 1, c);
  48.         } else if (b - 1 == 11) {
  49.             return 30 + Mes(a, b - 1, c);
  50.         } else if (b - 1 == 12) {
  51.             return 31 + Mes(a, b - 1, c);
  52.         }
  53.         return 0;
  54.  
  55.     }
  56.  
  57.     public static void main(String[] args) {
  58.  
  59.         Scanner sc = new Scanner(System.in);
  60.         String dataInicial = sc.next();
  61.         String dataFinal = sc.next();
  62.  
  63.         String[] dataI = new String[3];
  64.         String[] dataF = new String[3];
  65.  
  66.         dataI = dataInicial.split("/");
  67.         dataF = dataFinal.split("/");
  68.  
  69.         int diai = Integer.parseInt(dataI[0]);
  70.         int mesi = Integer.parseInt(dataI[1]);
  71.         int anoi = Integer.parseInt(dataI[2]);
  72.  
  73.         int diaf = Integer.parseInt(dataF[0]);
  74.         int mesf = Integer.parseInt(dataF[1]);
  75.         int anof = Integer.parseInt(dataF[2]);
  76.  
  77.         int somaI = 0, somaF = 0;
  78.  
  79.         somaI = Ano(0, anoi);
  80.         somaI += Mes(0, mesi, anoi);
  81.         somaI += diai;
  82.  
  83.         somaF = Ano(0, anof);
  84.         somaF += Mes(0, mesf, anof);
  85.         somaF += diaf;
  86.        
  87.         System.out.print(somaF - somaI);
  88.  
  89.         sc.close();
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement