Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class JavaApplication16 {
- public static int a[][] = {{0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0}};
- static int diaspormes[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- public static void ImprimeMes(int ds, int ms, boolean bisiesto) {
- int i, j, c, cd;
- System.out.println("D\tL\tMa\tMi\tJ\tV\tS");
- System.out.println("===================================================");
- int diasdemes = diaspormes[ms - 1] + 1;
- if (ms == 2 && bisiesto) {
- diasdemes += 1;
- }
- c = 0;
- cd = 0;
- for (i = 0; i <= 5; i++) {
- for (j = 0; j <= 6; j++) {
- c = c + 1;
- if (c >= ds) {
- cd = cd + 1;
- }
- if (cd >= 1 && cd < diasdemes) {
- a[i][j] = cd;
- System.out.print(a[i][j] + "\t");
- } else {
- System.out.print(" \t");
- }
- }
- System.out.println();
- }
- System.out.println();
- }
- public static void main(String[] args) {
- int N, dim1, numeromes;
- // x = 6;
- String[] meses = {"Enero", "Febrero", "Marzo",
- "Abril", "Mayo", "Junio",
- "julio", " Agosto", "septiembre",
- "Octubre", "Noviembre", "Diciembre"};
- String[] diassemana = {"Lunes", "Martes", "Miércoles",
- "Jueves", "Viernes", "Sábado",
- "Domingo"};
- int codm[] = {0, 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5};
- dim1 = 1;//se calcula el primero
- int dia = 1;
- numeromes = Integer.parseInt(JOptionPane.showInputDialog("mes"));
- N = dim1 + codm[numeromes];
- String anio = JOptionPane.showInputDialog("año");
- int anionumero = Integer.parseInt(anio);
- String astring = anio.substring(2);
- int a = Integer.parseInt(astring);
- N += a + a / 4;
- if (anionumero > 1999) {
- N += 6;
- }
- //else N+0
- String mes = meses[numeromes - 1];
- System.out.println("El primer día de " + mes + " del año " + anio + " cayó en...");
- int diasemana = N % 7;
- //System.out.println(diasemana);
- System.out.println("=> " + diassemana[diasemana - 1]);
- boolean bisiesto = anionumero % 4 == 0;
- if (bisiesto) {
- System.out.println("El año fue bisiesto");
- } else {
- System.out.println("El año no fue bisiesto");
- }
- ImprimeMes(diasemana, numeromes, bisiesto);
- }
- }
- //cd:contador de dias
- //ds:dia de la semana
- //diml:dia en que comienza el mes 1(enero)
- //mes:mes que se desea imprimir
Advertisement
Add Comment
Please, Sign In to add comment