+ 2

Help with ( US date to EU date )

import java.util.*; public class Program { public static void main(String[] args) { Scanner s=new Scanner(System.in); String usdate=s.nextLine(); if(usdate.contains("/")){ String arr[]=usdate.split("/"); String month=arr[0],date=arr[1], year=arr[2]; System.out.println(date+"/"+month+"/"+year); } else if(usdate.contains(" ")){ usdate=usdate.replaceAll(" ","/").replaceAll (",","/"); usdate=usdate.replaceAll("January","1").replaceAll("February","2").replaceAll("March","3").replaceAll("April","4").replaceAll("May","5").replaceAll("June","6").replaceAll("July","7").replaceAll("August","8").replaceAll("September","9").replaceAll("October","10").replaceAll("November","11").replaceAll("December","12"); String arr[]=usdate.split("/"); String month=arr[0],date=arr[1], year=arr[2]; System.out.println(date+"/"+month+"/"+year); } }}

16th Apr 2020, 9:18 AM
Ajay
Ajay - avatar
3 Respostas
+ 3
Ajay it works for me Have a look at this code: https://code.sololearn.com/cH2DQz6H1IfN/?ref=app
16th Apr 2020, 5:37 PM
...
+ 3
Replace the 1st condition of else if with this statement and check whether it gives an error or not. usdate=usdate.replaceAll(", ","/").replaceAll (" ","/");
16th Apr 2020, 1:16 PM
...
+ 1
No, it gives only 1/1 ie. Date/month as output
16th Apr 2020, 4:50 PM
Ajay
Ajay - avatar