Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class coisas {
- public static int Ano(int a, int b) {
- if (b - 1 == 0) {
- return 0;
- } else if (b - 1 > a) {
- if (b % 400 == 0 | ((b -1) % 4 == 0 && (b-1) % 100 != 0)) {
- return 366 + Ano(a, b - 1);
- } else {
- return 365 + Ano(a, b - 1);
- }
- }
- return 0;
- }
- public static int Mes(int a, int b, int c) {
- if (b - 1 == a) {
- return 0;
- } else if (b - 1 == 1) {
- return 31 + Mes(a, b - 1, c);
- } else if (b - 1 == 2) {
- if (c % 400 == 0 | (c % 4 == 0 && c % 100 != 0)) {
- return 29 + Mes(a, b - 1, c);
- } else {
- return 28 + Mes(a, b - 1, c);
- }
- } else if (b - 1 == 3) {
- return 31 + Mes(a, b - 1, c);
- } else if (b - 1 == 4) {
- return 30 + Mes(a, b - 1, c);
- } else if (b - 1 == 5) {
- return 31 + Mes(a, b - 1, c);
- } else if (b - 1 == 6) {
- return 30 + Mes(a, b - 1, c);
- } else if (b - 1 == 7) {
- return 31 + Mes(a, b - 1, c);
- } else if (b - 1 == 8) {
- return 31 + Mes(a, b - 1, c);
- } else if (b - 1 == 9) {
- return 30 + Mes(a, b - 1, c);
- } else if (b - 1 == 10) {
- return 31 + Mes(a, b - 1, c);
- } else if (b - 1 == 11) {
- return 30 + Mes(a, b - 1, c);
- } else if (b - 1 == 12) {
- return 31 + Mes(a, b - 1, c);
- }
- return 0;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String dataInicial = sc.next();
- String dataFinal = sc.next();
- String[] dataI = new String[3];
- String[] dataF = new String[3];
- dataI = dataInicial.split("/");
- dataF = dataFinal.split("/");
- int diai = Integer.parseInt(dataI[0]);
- int mesi = Integer.parseInt(dataI[1]);
- int anoi = Integer.parseInt(dataI[2]);
- int diaf = Integer.parseInt(dataF[0]);
- int mesf = Integer.parseInt(dataF[1]);
- int anof = Integer.parseInt(dataF[2]);
- int somaI = 0, somaF = 0;
- somaI = Ano(0, anoi);
- somaI += Mes(0, mesi, anoi);
- somaI += diai;
- somaF = Ano(0, anof);
- somaF += Mes(0, mesf, anof);
- somaF += diaf;
- System.out.print(somaF - somaI);
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement