I have to show how many days are left for his birthday given the date of birth, I have this code.
public class EjercicioJava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String nombre, papellido,sapellido,direccion,poblacion, foto;
Integer telefono;
Scanner entrada= new Scanner(System.in);
System.out.println("Introduce nombre");
nombre= entrada.nextLine();
System.out.println("Introduce 1er apellido");
papellido= entrada.nextLine();
System.out.println("Introduce 2o apellido");
sapellido= entrada.nextLine();
System.out.println("Introduce dirección");
direccion= entrada.nextLine();
System.out.println("Introduce población");
poblacion= entrada.nextLine();
System.out.println("Introduzca telefono");
telefono= entrada.nextInt();
System.out.println("Introduce foto");
foto= entrada.nextLine();
System.out.println("Usted se llama "+nombre+ " " + papellido + " " + sapellido + " ,con dirección " +direccion + " ,/n vive en " +poblacion+ " y cumple años dentro de " + meses + " meses y " + dias + " dias");
}
}
Here I leave you a complete method that calculates how many months and days are left for the next birthday, also determining if the birthday is today.
The method would be this, which you can refine, in terms of how to print or return the birthday calculation.
It also handles possible exceptions, such as wrong dates, so that the application doesn't stop in those cases.
To use it would be as simple as doing this, let's see tests with several dates:
Output of the three tests:
test code
You can see a code test in Rextester:VER DEMO
I would need to request the date of birth and subtract it from the current date, like this: