Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your task is to extract the dates and the corresponding number of lightning stri

ID: 3718741 • Letter: Y

Question

Your task is to extract the dates and the corresponding number of lightning strikes

2014-04-10 :   1 lightning strikes were recorded.

2014-04-21 :   19 lightning strikes were recorded.

                        *

                        *         

                        *

2014-09-03 :   102 lightning strikes were recorded.

See if you can output the data with a more familiar date format:

(Hint: split the date and rearrange the elements)

04 10 2014 : 1 lightning strikes were recorded.

04 21 2014 : 19 lightning strikes were recorded.

                                    *

                                    *

                                    *

09 03 2014 : 102 lightning strikes were recorded.

Explanation / Answer

package chegg;

import java.util.Scanner;

/**
*
* @author Sai_Kameswari
*/
public class q1 {
  
public static void main(String[] args) {
//assuming the input is given through scanner in java
Scanner s = new Scanner(System.in);
String input = s.nextLine();   
  
String[] light_array = input.split(",");
String date = light_array[0];
  
String[] date_array = date.split("-");
  
//Display output by rearranging the elements in arrays as necessary.
//This solution is for single input only and can be expanded to take multiple inputs by either using a file or while loop.
  
System.out.println(date_array[2] + " " + date_array[1] + " " + date_array[0] + " : " + light_array[3] + " lightning strikes were recorded.");
s.close();
}   
}