Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class magicDates
- {
- /*
- Question 1
- The Question
- The date 10th June 1960 is special because when we write it in the following format, the month times
- the day equals the year: 10/6/60
- Using Eclipse create a project and a class (named magicDates) to write a Java program that asks the
- user to enter a month (in numeric form), a day, and a two-digit year. The program should then determine
- whether the day times the month is equal to the year; if so, it should display a message indicating that
- the date is magic. Otherwise, it should display a message indicating that the date is not magic. Your
- program code should incorporate an appropriate loop to ensure that the value for the year that is
- entered by the user is in the range 1 to 99 (note: for the purpose of this exercise you do not need to
- validate the day or month values). 50768.
- Include in the comments at the top of the program:
- - your student id,
- - your full name,
- - campus,
- - practical class day and time
- - tutors name
- */
- public static void main(String[] args)
- {
- int day, month, year;
- Scanner keyboard = new Scanner(System.in);
- System.out.println("What is the day?");
- day = keyboard.nextInt();
- System.out.println("What is the month?");
- month = keyboard.nextInt();
- System.out.println("What year is it?");
- year = keyboard.nextInt();
- /*Loop that keeps asking for a new Year to be entered, if the year entered is invalid,
- i.e. not between 1 and 99.*/
- while ( (year < 1) || (year > 99) )
- {
- System.out.println("Please re-enter a valid year (1-99.)");
- year = keyboard.nextInt();
- }
- if ( (day * month) == year )
- {
- System.out.println("\nYou entered a Magic Date!");
- }
- else
- {
- System.out.println("\nThe date entered is not a Magic Date.");
- }
- keyboard.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement