hpilo

Chapter2_SyntaxA_Ex9

Dec 15th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.       Chapter 2: Syntax section A- conditional clause
  5.  
  6.                Ex9: Date Display
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         double date;
  15.         int year,month,day;
  16.         Scanner s=new Scanner(System.in);
  17.  
  18.         //user input
  19.         System.out.println("\nEnter a date: ");
  20.         date=s.nextDouble();
  21.  
  22.         //separate number accordingly
  23.         year=(int)date%10000;
  24.         month=(int)(date/10000)%100;
  25.         day=(int)(date/1000000);
  26.  
  27.         //display date
  28.         System.out.println("The year is "+year +", the month is "+month +", and the day is "+day+".");
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment