Design and implement a program that accept date as input. The program should display the date position in that year. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
- 1

Design and implement a program that accept date as input. The program should display the date position in that year.

Design and implement a program that accept date as input. The program should display the date position in that year. For example, if the date is 12 29 2019, then the displayed number is 363.

13th Aug 2019, 9:50 AM
Mohammed Mutawakil
Mohammed Mutawakil - avatar
2 ответов
+ 3
Plz show us your attempt so that we can help you.
13th Aug 2019, 10:19 AM
Rstar
Rstar - avatar
+ 1
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Scanner; public class Datinput { public static void main(String args[]) { int n; ArrayList<String> al = new ArrayList<String>(); Scanner in = new Scanner(System.in); n = in.nextInt(); String da[] = new String[n]; SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); sdf.setLenient(false); Date date[] = new Date[n]; in.nextLine(); for (int i = 0; i < da.length; i++) { da[i] = in.nextLine(); } for (int i = 0; i < da.length; i++) { try { date[i] = sdf.parse(da[i]); } catch (ParseException e) { e.printStackTrace(); } } in.close(); } }
13th Aug 2019, 10:43 AM
Mohammed Mutawakil
Mohammed Mutawakil - avatar