“Nunca he encontrado una persona tan ignorante que no pueda aprender algo de ella.”

lunes, 15 de mayo de 2017

calendario java

Haz un calendario que te liste los días del año según el día que empezó ese año, según si es bisiesto o no, y teniendo en cuenta de que cada semana se salta de línea.



import java.util.*;
public class HelloWorld{

     public static void main(String []args){
       Scanner anio = new Scanner(System.in);
       int anno;
Scanner dio = new Scanner(System.in);
int dia;
       Scanner dias = new Scanner(System.in);
       String seman;
   
        System.out.println ("Que anno buscas?");
        anno = anio.nextInt();
        System.out.println ("Si lunes fuese -1, martes 0, miercoles 1 y etc, que dia empezo el anno?");
       dia = dio.nextInt();


System.out.println("Que dia comenzo ese anno?");
        seman = dias.nextLine();
            if (seman.equals("lunes")){
                int seman2 = -1;
               
            }else if (seman.equals("martes")){
                int seman2 = 0;
                System.out.print ("   ");
            }else if (seman.equals("miercoles")){
                int seman2 = 1;
                 System.out.print ("      ");
            }else if (seman.equals("jueves")){
                int seman2 = 2;
                 System.out.print ("         ");
            }else if (seman.equals("viernes")){
                int seman2 = 3;
                System.out.print ("            ");
            }else if (seman.equals("sabado")){
                int seman2 = 4;
                System.out.print ("               ");
            }else if (seman.equals("domingo")){
                int seman2 = 5;
                System.out.print ("                  ");
            }
       
       
         if (anno % 4 == 0 && anno % 400 == 0){
                for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=29; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 29 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 29 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 29 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 29 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 29 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
               
               
            }else if (anno % 4 == 0 && anno % 100 != 0){
                for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=29; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 29 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 29 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 29 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 29 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 29 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
               
               
            }else if (anno % 4 == 0 && anno % 400 != 0){
                for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=28; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 28 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 28 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 28 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 28 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 28 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                }else{
                 for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=28; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 28 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 28 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 28 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 28 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 28 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
               
            }
         }
     }