Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/FizzBuzz/Java/fizzbuzz-1.java
Normal file
15
Task/FizzBuzz/Java/fizzbuzz-1.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
public class FizzBuzz {
|
||||
public static void main(String[] args) {
|
||||
for (int number = 1; number <= 100; number++) {
|
||||
if (number % 15 == 0) {
|
||||
System.out.println("FizzBuzz");
|
||||
} else if (number % 3 == 0) {
|
||||
System.out.println("Fizz");
|
||||
} else if (number % 5 == 0) {
|
||||
System.out.println("Buzz");
|
||||
} else {
|
||||
System.out.println(number);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Task/FizzBuzz/Java/fizzbuzz-2.java
Normal file
17
Task/FizzBuzz/Java/fizzbuzz-2.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
public class FizzBuzz {
|
||||
public static void main(String[] args) {
|
||||
int number = 1;
|
||||
while (number <= 100) {
|
||||
if (number % 15 == 0) {
|
||||
System.out.println("FizzBuzz");
|
||||
} else if (number % 3 == 0) {
|
||||
System.out.println("Fizz");
|
||||
} else if (number % 5 == 0) {
|
||||
System.out.println("Buzz");
|
||||
} else {
|
||||
System.out.println(number);
|
||||
}
|
||||
number++;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Task/FizzBuzz/Java/fizzbuzz-3.java
Normal file
9
Task/FizzBuzz/Java/fizzbuzz-3.java
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
public class FizzBuzz {
|
||||
public static void main(String[] args) {
|
||||
int number = 1;
|
||||
while (number <= 100) {
|
||||
System.out.println(number % 15 == 0 ? "FizzBuzz" : number % 3 == 0 ? "Fizz" : number % 5 == 0 ? "Buzz" : number);
|
||||
number++;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Task/FizzBuzz/Java/fizzbuzz-4.java
Normal file
14
Task/FizzBuzz/Java/fizzbuzz-4.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import java.util.stream.IntStream;
|
||||
class FizzBuzzJdk12 {
|
||||
public static void main(String[] args) {
|
||||
IntStream.range(1,101)
|
||||
.mapToObj(i->switch (i%15) {
|
||||
case 0 -> "FizzBuzz";
|
||||
case 3, 6, 9, 12 -> "Fizz";
|
||||
case 5, 10 -> "Buzz";
|
||||
default -> Integer.toString(i);
|
||||
})
|
||||
.forEach(System.out::println)
|
||||
;
|
||||
}
|
||||
}
|
||||
29
Task/FizzBuzz/Java/fizzbuzz-5.java
Normal file
29
Task/FizzBuzz/Java/fizzbuzz-5.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import java.util.stream.IntStream;
|
||||
|
||||
class FizzBuzzJdk12 {
|
||||
static final int FIZZ_FLAG = 0x8000_0000;
|
||||
static final int BUZZ_FLAG = 0x4000_0000;
|
||||
static final int FIZZ_BUZZ_FLAG = FIZZ_FLAG|BUZZ_FLAG;
|
||||
static final int[] FLAGS = new int[] {
|
||||
FIZZ_BUZZ_FLAG|0, 1, 2, FIZZ_FLAG|3, 4,
|
||||
BUZZ_FLAG|5, FIZZ_FLAG|6, 7, 8, FIZZ_FLAG|9,
|
||||
BUZZ_FLAG|10, 11, FIZZ_FLAG|12, 13, 14
|
||||
};
|
||||
public static void main(String[] args) {
|
||||
IntStream.iterate(0,i->++i)
|
||||
.flatMap(i -> IntStream.range(0,15).map(j->FLAGS[j]+15*i))
|
||||
.mapToObj(
|
||||
// JDK12 switch expression ...
|
||||
n-> switch(n & FIZZ_BUZZ_FLAG) {
|
||||
case FIZZ_BUZZ_FLAG -> "fizzbuzz";
|
||||
case FIZZ_FLAG -> "fizz";
|
||||
case BUZZ_FLAG -> "buzz";
|
||||
default -> Integer.toString(~FIZZ_BUZZ_FLAG & n);
|
||||
}
|
||||
)
|
||||
.skip(1)
|
||||
.limit(100)
|
||||
.forEach(System.out::println)
|
||||
;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue