UNA HERMOSA MOTO

UNA HERMOSA MOTO

domingo, 5 de abril de 2015

DIAS DEL MES



ESTE PROGRAMA NOS VA A DAR EL NÚMERO DE DÍAS DE UN DETERMINADO MES, Y SI ES DE UN AÑO BISIESTO NOS DARÁ COMO RESULTADO "29" SI ES QUE CONSULTAMOS LOS DÍAS DE FEBRERO.

INGRESAREMOS UN NÚMERO DEL MES (DEL 1 AL 12) Y UN AÑO CUALQUIERA. SI ES ENERO DIGITAREMOS 1, SI QUEREMOS CONSULTAR LOS DÍAS DE FEBRERO DIGITAREMOS 2 Y ASÍ SUCESIVAMENTE HASTA EL 12).

SI INGRESAMOS 1 COMO MES Y 2015 COMO AÑO, EL PROGRAMA NOS DARÁ COMO RESULTADO: 31.

SI INGRESAMOS CUALQUIER OTRO NÚMERO FUERA DEL RANGO DEL 1 AL 12, EL PROGRAMA ARROJARÁ UN  MENSAJE DE ERROR.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package diasmes;
import java.io.*;
/**
 *
 * @author abel montalv an
 */
public class Diasmes {

public static void main(String args[])throws IOException{

int año,mes,dia=0;

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Escribe el número del mes: ");

mes=Integer.parseInt(in.readLine());
 
System.out.println("Escribe el número del año : ");

año=Integer.parseInt(in.readLine());


switch(mes)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:dia=31;

break;

case 4:

case 6:

case 9:

case 11:dia=30;

break;

case 2:


    if(año % 4 == 0 && año % 100 != 0 || año % 400 == 0)
        {dia=29;}

else{dia=28;}

//{System.out.println("El mes "+ms+" del año "+a+" tiene "+dias+" dias"); }

}

{System.out.println("El mes "+mes+" del año "+año+" tiene "+dia+" dias"); }

if (mes<1^mes>12)

{System.out.println("porque es un mes incorrecto");}



}
}

No hay comentarios:

Publicar un comentario