Showing posts with label NUMBER OF YEARS. Show all posts
Showing posts with label NUMBER OF YEARS. Show all posts

Sunday, April 1, 2018

NUMBER OF YEARS, WEEK AND DAYS USING EXCEPTION IN JAVA

Here is a sample program will count the number of years, weeks, and  days using Java as our programming language.  

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output


Program Listing

Days.java


package exceptiondemo;

import java.util.Scanner;
import java.util.InputMismatchException;

/**
 * NetBeans IDE 8.2
 * @author Mr. Jake R. Pomperada
 * March 20, 2018  Tuesday
 * Bacolod City, Negros Occidental
 */
public class Days {

   public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);

               int  year=0, week=0, day=0;

               boolean goodData = false;
                
              while(!goodData) {

              try {
                System.out.print("NUMBER OF YEARS, WEEK AND DAYS USING EXCEPTION");
                System.out.println("\n");
                System.out.print("Give Number of Days  : ");
int num_days =sc.nextInt();
                
                year = (num_days/ 365);
                num_days = (num_days % 365);
                System.out.println("Number of years:" +year + ".");
                 week = (num_days / 7);
                 num_days = (num_days % 7);
                System.out.println("Number of weeks:" + week + ".");
                day = num_days;
                System.out.println("Number of days:" + day + ".");
                System.out.println("\n");
goodData = true;
       
              } catch(InputMismatchException e) {
            
                sc.next();
                System.out.println("You Entered a Bad Data." );
                System.out.println("Please Try Again." );
                System.out.println("\n");
                }
            }  // while loop end
System.out.print("\t END OF PROGRAM");
        System.out.println("\n");
     }
}