Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do you solve the dayOfTheWeek program with basic code?

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you solve the dayOfTheWeek program with basic code?

    Write a program that prompts the user to enter a date, using integer values for the month, day, and year, and then prints out the day of the week that fell on that date.

    According to the Gregorian Calendar, January 1, 1601 was a Monday. Observe all leap years (and keep in mind that 1700, 1800, and 1900 were not leap years).
    ------------------------------------what I have so far is below, besides that I am stuck------------------------------------------------------------------------
    import java.util.*;
    public class DayOfTheWeek {
    public static void main(String args[]) {
    userInput();
    leapYearCheck();
    }

    public static void userInput(){
    Scanner console = new Scanner(System.in);
    int month;
    int day;
    int year;
    System.out.print("Enter month:");
    month = console.nextInt();
    System.out.print("Enter day:");
    day = console.nextInt();
    System.out.print("Enter year:");
    /* solves for the leap year */
    if( (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
    year = 1601 +3;

    }



    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do you solve the dayOfTheWeek program with basic code?

    Do you have to do all the calculations yourself or can you use a class like Calendar?
    If you have to do the math, then you will need to find an algorithm for that.


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. HELP ME TO SOLVE THIS JAVA FOR LOOP PROGRAM
    By muhammad waqar in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2012, 03:17 PM
  2. How to solve “NullPointerException” in my Java Program ?
    By unknowny in forum Java Theory & Questions
    Replies: 8
    Last Post: July 24th, 2012, 04:06 PM
  3. can anyone help me solve this code
    By sudeep22 in forum Other Programming Languages
    Replies: 1
    Last Post: September 25th, 2011, 10:18 PM
  4. how I can solve this program ?
    By Noni in forum Object Oriented Programming
    Replies: 9
    Last Post: January 20th, 2011, 05:33 PM
  5. help me out with the following code to solve the error
    By romilc in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 11th, 2009, 03:45 AM