In: Computer Science
Write a Java console application that reads a string for a date in the U.S. format MM/DD/YYYY and displays it in the European format DD.MM.YYYY For example, if the input is 02/08/2017, your program should output 08.02.2017
package org.students;
import java.util.Scanner;
public class ReadDate {
public static void main(String[] args) {
//Declaring variables
String usFDate;
String mon,day,yr;
//Scanner object is used to get the
inputs entered by the user
Scanner sc=new
Scanner(System.in);
//Getting the date entered by the
user as string
System.out.print("Enter the date in
US Format (MM/DD/YYYY) :");
usFDate=sc.nextLine();
//Getting the Month by using the
subString()method of String class
mon=usFDate.substring(0,usFDate.indexOf('/'));
//Getting the day
day=usFDate.substring(usFDate.indexOf('/')+1,usFDate.lastIndexOf('/'));
//Getting the year
yr=usFDate.substring(usFDate.lastIndexOf('/')+1,usFDate.length());
//Displaying the year in european
format
System.out.println("Date in
Europian Format (DD.MM.YYYY) :"+day+"."+mon+"."+yr);
}
}
________________________
output:
Enter the date in US Format (MM/DD/YYYY) :12/31/2015
Date in Europian Format (DD.MM.YYYY) :31.12.2015
___________Thank You