The date June 10, 1960, is special because when you write it in the following format, the month times the day equals the
year. 6/10/60
Write a program that asks the user for the month as a numeric, a day, and a two-digit year. The program should then
determine whether the month times the day is equal to the year. If so, display a message saying the date is magic;
otherwise, display a message saying the date is not magic.
year. 6/10/60
Write a program that asks the user for the month as a numeric, a day, and a two-digit year. The program should then
determine whether the month times the day is equal to the year. If so, display a message saying the date is magic;
otherwise, display a message saying the date is not magic.
1 package chapter4; 2 3 import java.util.Scanner; 4 5 public class MagicDates { 6 7 public static void main(String[] args) { 8 9 Scanner scan = new Scanner(System.in); 10 11 int month, day, year; 12 13 System.out.print("Enter month, day and 2 digit year: "); 14 month = scan.nextInt(); 15 day = scan.nextInt(); 16 year = scan.nextInt(); 17 18 if((month * day) == year) 19 { 20 System.out.println("Date is magic!"); 21 } 22 else 23 { 24 System.out.println("Date is not magic!"); 25 } 26 27 } 28 29 } 30
No comments:
Post a Comment