Wednesday, March 18, 2015

Count the number of years and weeks in a given days in Java


In this article I would like to share with you a sample program that I wrote using JAVA I called this program Count Years or Weeks  in a given days Using JAVA. The code is very simple by the use of simple formulas I hope you will find my work useful in your programming assignments and projects in JAVA.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360





SAMPLE OUTPUT OF OUR PROGRAM


Program Listing

import java.util.Scanner;


class year_count
{

  public static int solve_it(int days)
   {
 int years=0,solve=0,weeks=0;
 years = days/365;
 solve=days-(years*365);
 weeks=days/7;
      solve=days-(weeks*7);
      System.out.println(years + " Year(s) or " + weeks + " Week(s).");
      return 0;
    }

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

 int no_days=0;

 System.out.print("\n");
 System.out.println("=============================================================");
 System.out.println("||   <<< COUNT NO. OF YEARS OR WEEKS IN A GIVEN DAYS >>>   ||");
 System.out.println("=============================================================");
     System.out.print("\n");
     System.out.print("Enter Number of Days :=> ");
          no_days = in.nextInt();

     System.out.println("\n");
 System.out.println("=======================");
 System.out.println("||  DISPLAY RESULT   ||");
 System.out.println("=======================");
 System.out.println("\n");
          solve_it(no_days);


          System.out.println("\n\n");
          System.out.print("Do you Want To Continue (Y/N) :=> ");
           a=in.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
}
}



No comments:

Post a Comment