Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section A- conditional clause
- Ex9: Date Display
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- double date;
- int year,month,day;
- Scanner s=new Scanner(System.in);
- //user input
- System.out.println("\nEnter a date: ");
- date=s.nextDouble();
- //separate number accordingly
- year=(int)date%10000;
- month=(int)(date/10000)%100;
- day=(int)(date/1000000);
- //display date
- System.out.println("The year is "+year +", the month is "+month +", and the day is "+day+".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment