From a840b4eab63340e138e4c9347c5f23b8c3da02f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C5=A1per=20Dobrovoljc?= Date: Mon, 18 Mar 2024 22:47:09 +0100 Subject: [PATCH] DN03 --- gesla.txt | 5 +++++ src/DN03.java | 36 ++++++++++++++++++++++++++++++++++++ src/Vaja02Fakulteta.java | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gesla.txt create mode 100644 src/DN03.java diff --git a/gesla.txt b/gesla.txt new file mode 100644 index 0000000..c1a7ce6 --- /dev/null +++ b/gesla.txt @@ -0,0 +1,5 @@ +4 +abcdefghijklmnoprstuvz +XYQW +0123456789 +_-#@ \ No newline at end of file diff --git a/src/DN03.java b/src/DN03.java new file mode 100644 index 0000000..e550ee7 --- /dev/null +++ b/src/DN03.java @@ -0,0 +1,36 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Random; +import java.util.Scanner; + +public class DN03 { + public static void main(String[] args) { + File file = new File(args[0]); + Scanner scanner; + try { + scanner = new Scanner(file); + } catch (FileNotFoundException e) { + System.err.println("Datoteka ne obstaja"); + return; + } + + int len = Integer.parseInt(scanner.nextLine()); + String[] besede = new String[len]; + + for (int i = 0; i < len; i++) { + besede[i] = scanner.nextLine(); + } + scanner.close(); + + int n = Integer.parseInt(args[1]); + Random random = new Random(Integer.parseInt(args[2])); + + StringBuilder geslo = new StringBuilder(); + for (int i = 0; i < n; i++) { + String beseda = besede[random.nextInt(len)]; + geslo.append(beseda.charAt(random.nextInt(beseda.length()))); + } + + System.out.println(geslo); + } +} diff --git a/src/Vaja02Fakulteta.java b/src/Vaja02Fakulteta.java index 98fea16..70d84da 100644 --- a/src/Vaja02Fakulteta.java +++ b/src/Vaja02Fakulteta.java @@ -2,7 +2,7 @@ public class Vaja02Fakulteta { public static void main(String[] args) { // izpisL(); // izpisD(); -// izpisPiNilakantha(); + // izpisPiNilakantha(); System.out.println(izracunajPi(5)); }