lr1 -> task_1 -> e3-e8

This commit is contained in:
2026-04-05 20:39:21 +05:00
parent a2b7572206
commit 500c41df80
7 changed files with 214 additions and 0 deletions

34
lr10/task_1/e3.java Normal file
View File

@@ -0,0 +1,34 @@
package lr10.task_1;
import java.io.FileWriter;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class e3 {
public static void main(String[] args) {
JSONObject library = new JSONObject();
JSONArray books = new JSONArray();
JSONObject book1 = new JSONObject();
book1.put("title", "Война и мир");
book1.put("author", "Лев Толстой");
book1.put("year", 1869);
JSONObject book2 = new JSONObject();
book2.put("title", "Мастер и Маргарита");
book2.put("author", "Михаил Булгаков");
book2.put("year", 1967);
books.add(book1);
books.add(book2);
library.put("books", books);
try (FileWriter file = new FileWriter("example-json.json")) {
file.write(library.toJSONString());
System.out.println("Json файл успешно создан!");
} catch (Exception e) {
e.printStackTrace();
}
}
}