Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Our Q&A platform offers a seamless experience for finding reliable answers from experts in various disciplines. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.
Sagot :
Answer:
Explanation:
The following is written in Java and takes in a single input, tests if it is in the correct format and then outputs the new desired format.
import java.util.*;
import java.util.regex.Pattern;
class ChangeDate
{
public static void main(String args[])
{
String mo,da,yr;
Scanner input=new Scanner(System.in);
boolean next = true;
while (next == true) {
System.out.print("Enter month::");
String userDate = input.nextLine();
if (userDate.equals("-1")) {
next = false;
}
if (Pattern.matches("\\d\\d\\S\\d\\d\\S\\d\\d\\d\\d", userDate)) {
mo = userDate.substring(0, 2);
da = userDate.substring(3, 5);
yr = userDate.substring(6, 10);
System.out.println(getMonth(mo) + " " + da + ", " + yr);
}
}
}
public static String getMonth(String month) {
switch (month) {
case "01":
return "January";
case "02":
return "February";
case "03":
return "March";
case "04":
return "April";
case "05":
return "May";
case "06":
return "June";
case "07":
return "July";
case "08":
return "August";
case "09":
return "September";
case "10":
return"October";
case "11":
return"November";
case "12":
return "December";
default:
return "Wrong Month Date";
}
}}
Thank you for choosing our service. We're dedicated to providing the best answers for all your questions. Visit us again. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. Westonci.ca is committed to providing accurate answers. Come back soon for more trustworthy information.