Make this loop simple (print Letter J in Java using loop)
Date : March 29 2020, 07:55 AM
this will help I try to print letter D on console, but I couldn't help the code is longer than my expectation. Could you help me.... there are another way to reduce this code? Thank you. This is my code: , Helper methods simply your code a lot: public static void main(String[] args) {
printAsterisks(11, true);
printAsterisks(13, true);
for(int i = 6; i < 10; i++){
printSpaced(i);
}
for(int i = 10; i > 5; i--){
printSpaced(i);
}
printAsterisks(13, true);
printAsterisks(11, true);
}
static void printSpaced(int spaces){
printAsterisks(4, false);
for(int i = 0; i < spaces; i++){
System.out.print(" ");
}
printAsterisks(4, true);
}
static void printAsterisks(int n, boolean newLine){
for(int i = 0; i < n; i++){
System.out.print('*');
}
if(newLine){
System.out.println("");
}
}
|
Can't find issue in simple js for-loop
Date : March 29 2020, 07:55 AM
this will help Change newArray() to new Array() I believe that is what is causing your error sir. Good luck! if (id[randomid] === null) {
if (id[randomid] == null) {
|
Why simple Scala tailrec loop for fibonacci calculation is faster in 3x times than Java loop?
Tag : java , By : nonkelhans
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Yes, I was wrong, and missed that tested method was not just fastLoop calls: Scala @Benchmark
def loop(): BigInt =
if (n > 92) loop(n - 91, 4660046610375530309L, 7540113804746346429L)
else fastLoop(n)
@Benchmark
public BigInteger loop() {
return n > 92 ?
loop(n - 91, BigInteger.valueOf(4660046610375530309L), BigInteger.valueOf(7540113804746346429L)) :
BigInteger.valueOf(fastLoop(n, 0, 1));
}
[info] JavaFibonacci.fastLoop 2 thrpt 5 338071686.910 ± 66146042.535 ops/s
[info] JavaFibonacci.fastLoop 4 thrpt 5 231066635.073 ± 3702419.585 ops/s
[info] JavaFibonacci.fastLoop 8 thrpt 5 174832245.690 ± 36491363.939 ops/s
[info] JavaFibonacci.fastLoop 16 thrpt 5 95162799.968 ± 16151609.596 ops/s
[info] JavaFibonacci.fastLoop 32 thrpt 5 60197918.766 ± 10662747.434 ops/s
[info] JavaFibonacci.fastLoop 64 thrpt 5 29564087.602 ± 3610164.011 ops/s
[info] ScalaFibonacci.fastLoop 2 thrpt 5 336588218.560 ± 56762496.725 ops/s
[info] ScalaFibonacci.fastLoop 4 thrpt 5 224918874.670 ± 35499107.133 ops/s
[info] ScalaFibonacci.fastLoop 8 thrpt 5 121952667.394 ± 17314931.711 ops/s
[info] ScalaFibonacci.fastLoop 16 thrpt 5 96573968.960 ± 12757890.175 ops/s
[info] ScalaFibonacci.fastLoop 32 thrpt 5 59462408.940 ± 14924369.138 ops/s
[info] ScalaFibonacci.fastLoop 64 thrpt 5 28922994.377 ± 7209467.197 ops/s
|
making a simple math quiz with switch statement for loop and while loop in java
Date : March 29 2020, 07:55 AM
|
While building a simple application using bazel getting error Couldn't find java at '/usr/lib/java/jdk1.8.0_74/bin/java'
Date : March 29 2020, 07:55 AM
|