JAVA-625: Moved 3 articles from java-numbers-2 to java-numbers-3

This commit is contained in:
sampadawagde
2020-03-25 23:06:05 +05:30
parent 923db8ed15
commit e02385f91d
6 changed files with 0 additions and 2 deletions

View File

@@ -1,34 +0,0 @@
package com.baeldung.fibonacci;
import static java.lang.Math.pow;
public class FibonacciSeriesUtils {
public static int nthFibonacciTermRecursiveMethod(int n) {
if (n == 0 || n == 1) {
return n;
}
return nthFibonacciTermRecursiveMethod(n - 1) + nthFibonacciTermRecursiveMethod(n - 2);
}
public static int nthFibonacciTermIterativeMethod(int n) {
if (n == 0 || n == 1) {
return n;
}
int n0 = 0, n1 = 1;
int tempNthTerm;
for (int i = 2; i <= n; i++) {
tempNthTerm = n0 + n1;
n0 = n1;
n1 = tempNthTerm;
}
return n1;
}
public static int nthFibonacciTermUsingBinetsFormula(int n) {
final double squareRootOf5 = Math.sqrt(5);
final double phi = (1 + squareRootOf5)/2;
int nthTerm = (int) ((Math.pow(phi, n) - Math.pow(-phi, -n))/squareRootOf5);
return nthTerm;
}
}

View File

@@ -1,36 +0,0 @@
package com.baeldung.numbersinrange;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class NumbersInARange {
public List<Integer> getNumbersInRange(int start, int end) {
List<Integer> result = new ArrayList<>();
for (int i = start; i < end; i++) {
result.add(i);
}
return result;
}
public List<Integer> getNumbersUsingIntStreamRange(int start, int end) {
return IntStream.range(start, end)
.boxed()
.collect(Collectors.toList());
}
public List<Integer> getNumbersUsingIntStreamRangeClosed(int start, int end) {
return IntStream.rangeClosed(start, end)
.boxed()
.collect(Collectors.toList());
}
public List<Integer> getNumbersUsingIntStreamIterate(int start, int limit) {
return IntStream.iterate(start, i -> i + 1)
.limit(limit)
.boxed()
.collect(Collectors.toList());
}
}

View File

@@ -1,22 +0,0 @@
package com.baeldung.numbersinrange;
import java.util.Random;
public class RandomNumbersInARange {
public int getRandomNumber(int min, int max) {
return (int) ((Math.random() * (max - min)) + min);
}
public int getRandomNumberUsingNextInt(int min, int max) {
Random random = new Random();
return random.nextInt(max - min) + min;
}
public int getRandomNumberUsingInts(int min, int max) {
Random random = new Random();
return random.ints(min, max)
.findFirst()
.getAsInt();
}
}