Please solve this problem in JAVA ASAP. Thanks
in Advance!
// DO NOT MODIFY GIVEN CODE.
Problem Statement:
Consider an input string array, inStrArr
(String[]) containing dates in the format
"dd/mm/yyyy" as its input values.
Write a JAVA method which
takes inStrArr as input parameter and
returns an outStrArr (String[]) as per logic
given below:
-> For every element in the inStrArr,
1. Make a new
string, str1 by concatenating
"dd" and "mm" of the date .
2. If
"yyyy" can be ontained upon any circular rotation
of str1, add the year to the
outStrArr.
3. Otherwise, add
"X"(uppercase to the outStrArr.
Assumptions:
-> inStrArr would not be empty
NOTE:
-> The size of outStrArr would be the
same as inStrArr.
-> No need to validate assumption.
Input Format:
-> First line will contain the elements of
inStrArr with the elements seperated by ","
(comma
Read the inputs from the standard input stream.
Output Format:
Print the values of outStrArr, seperated by
","(comma), to the standard output stream.
Example:
inStrArr1: {"03/11/1103","24/02/1991","31/01/1031","20/02/2002"}
outStrArr: {"1103", "X", "X", "2002"}
Explanation:
-> The first element of inStrArr is
"03/11/1103", thus combining "dd" and "mm" gives "0311" which is
str1. The different circular rotations for "0311" are "0311",
"3110", "1103", "1031". One circular rotation of str1 is the same
as year. Hence add year to outStrArr.
Now, the outStrArr will be
{"1103"}
->The second element
of inStrArr is "24/02/1991", thus
combining "dd" and "mm" gives "2402" which is str1. The different
circular rotations for "2402" are "2402", "4022", "0224", "2240".
None of the circular rotations of str1 is same as year. Hence add
"X" to outStrArr.
Now, the outStrArr will be {"1103",
"X"}
-> The next element of inStrArr is
"31/01/1031", thus combining "dd" and "mm" gives "3101" which is
str1. The different circular rotations for "3101" are "3101",
"1013", "0131", "1310". None of the circular rotation of str1 is
same as year. Hence add "X" to outStrArr.
Now, the outStrArr will be {"1103",
"X", "X"}
-> The next element
of inStrArr is "20/02/2002", thus
combining "dd" and "mm" gives "2002" which is str1. The
different circular rotations for "2002" are "2002", "0022", "2200".
One circular rotation of str1 is same as year. Hence add year
to outStrArr.
Now, the outStrArr will be {"1103",
"X", "X", "2002"}
13/13/1313,14/11/1817,09/10/1009,
23/05/1012,12/06/1206,21/05/1205
02/12/2120,11/10/1011,21/04/1042,23/02/2230
15/02/1988,09/01/1818,21/06/1988,21/02/1981
// DO NOT MODIFY THE CODE PROVIDED TO
YOU
class Solution{
public String[] dateDirectory(String[] inStrArr){
String[] outStrArr = new String
[inStrArr.length];
// Implement your
logic here
return outStrArr;
}
public static void main(String[] args){
// DO NOT Modify the below code. "Provide
custom input" as mentioned in the input format of the problem
description
Scanner sc = new Scanner(System.in);
// Accepting elements of
inStrArr
String[] inStrArr = sc.nextLine().split(",");
String[] outStrArr;
Solution testerobj1 = new Solution();
outStrArr = testerobj1.dateDirectory(inStrArr);
// Printing the elements of
outStrArr
if(outStrArr[0] != null)
{
for(int index = 0; index<outStrArr.length; index++)
{
if(index == outStrArr.length-1)
{
System.out.print(outStrArr[index]);
}
else {
System.out.print(outStrArr[index]+",");
}
}
}
else{
System.out.println("outStrArr is empty");
}
}
}
Please solve this problem in JAVA ASAP. Thanks in Advance! // DO NOT MODIFY GIVEN CODE. Problem Statement: Consider an
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Please solve this problem in JAVA ASAP. Thanks in Advance! // DO NOT MODIFY GIVEN CODE. Problem Statement: Consider an
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!