Compare commits
No commits in common. "a840b4eab63340e138e4c9347c5f23b8c3da02f7" and "8e0baa5eb75c6c656e9096a1de4c2e94d79a3ba1" have entirely different histories.
a840b4eab6
...
8e0baa5eb7
|
@ -1,36 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
public class Vaja02Fakulteta {
|
||||
public static void main(String[] args) {
|
||||
// izpisL();
|
||||
// izpisD();
|
||||
// izpisPiNilakantha();
|
||||
System.out.println(izracunajPi(5));
|
||||
}
|
||||
|
||||
|
||||
static long fakultetaL(int n) {
|
||||
long x = 1;
|
||||
while (n > 1) {
|
||||
x *= n;
|
||||
n--;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static long stirlingL(int n) {
|
||||
return Math.round(Math.sqrt(2 * Math.PI * n) * Math.pow(n / Math.E, n));
|
||||
}
|
||||
|
||||
static void izpisL() {
|
||||
System.out.println(
|
||||
" n n! Stirling(n) napaka (%)\n" +
|
||||
"----------------------------------------------------------"
|
||||
);
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
long fakulteta = fakultetaL(i);
|
||||
long stirling = stirlingL(i);
|
||||
float napaka = (1 - (float) stirling / fakulteta) * 100;
|
||||
|
||||
System.out.printf("%3d %20d %20d %10.7f\n", i, fakulteta, stirling, napaka);
|
||||
}
|
||||
}
|
||||
|
||||
static double fakultetaD(int n) {
|
||||
double x = 1;
|
||||
while (n > 1) {
|
||||
x *= n;
|
||||
n--;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static double stirlingD(int n) {
|
||||
return Math.sqrt(2 * Math.PI * n) * Math.pow(n / Math.E, n);
|
||||
}
|
||||
|
||||
static void izpisD() {
|
||||
System.out.println(
|
||||
" n n! Stirling(n) napaka (%)\n" +
|
||||
"----------------------------------------------------"
|
||||
);
|
||||
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
double fakulteta = fakultetaD(i);
|
||||
double stirling = stirlingD(i);
|
||||
double napaka = (1 - stirling / fakulteta) * 100;
|
||||
|
||||
System.out.printf("%3d %17.9E %17.9E %11.7f\n", i, fakulteta, stirling, napaka);
|
||||
}
|
||||
}
|
||||
|
||||
static double izracunajPiNilakantha(int k) {
|
||||
double x = 3;
|
||||
for (int i = 0; i < k; i++) {
|
||||
double a = 4.0 / ((2 + 2 * i) * (3 + 2 * i) * (4 + 2 * i));
|
||||
if (i % 2 == 0) {
|
||||
x += a;
|
||||
} else {
|
||||
x -= a;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static void izpisPiNilakantha() {
|
||||
System.out.println(" k Math.PI PI (Nilakantha) razlika \n" +
|
||||
"-----------------------------------------------------------------");
|
||||
for (int i = 1; i <= 22; i++) {
|
||||
double nilakantha = izracunajPiNilakantha(i);
|
||||
System.out.printf("%3d %19.15f %19.15f %+20.15f\n", i, Math.PI, nilakantha, Math.PI - nilakantha);
|
||||
}
|
||||
}
|
||||
|
||||
static double izracunajPi(int k) {
|
||||
double x = Math.pow(k, 2) / (k * 2 - 1);
|
||||
for (int i = k; i > 1; i--) {
|
||||
x = Math.pow(i - 1, 2) / (((i - 1) * 2 - 1) + x);
|
||||
}
|
||||
return 4 / x;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user