Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Nth/Java/nth-1.java
Normal file
26
Task/Nth/Java/nth-1.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
public class Nth {
|
||||
public static String ordinalAbbrev(int n){
|
||||
String ans = "th"; //most of the time it should be "th"
|
||||
if(n % 100 / 10 == 1) return ans; //teens are all "th"
|
||||
switch(n % 10){
|
||||
case 1: ans = "st"; break;
|
||||
case 2: ans = "nd"; break;
|
||||
case 3: ans = "rd"; break;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
for(int i = 0; i <= 25;i++){
|
||||
System.out.print(i + ordinalAbbrev(i) + " ");
|
||||
}
|
||||
System.out.println();
|
||||
for(int i = 250; i <= 265;i++){
|
||||
System.out.print(i + ordinalAbbrev(i) + " ");
|
||||
}
|
||||
System.out.println();
|
||||
for(int i = 1000; i <= 1025;i++){
|
||||
System.out.print(i + ordinalAbbrev(i) + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
48
Task/Nth/Java/nth-2.java
Normal file
48
Task/Nth/Java/nth-2.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package nth;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface Nth {
|
||||
public static String suffix(int n){
|
||||
if(n % 100 / 10 == 1){
|
||||
return "th"; //teens are all "th"
|
||||
}
|
||||
switch(n % 10){
|
||||
case 1: return "st";
|
||||
case 2: return "nd";
|
||||
case 3: return "rd";
|
||||
default: return "th"; //most of the time it should be "th"
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(int start, int end) {
|
||||
IntStream.rangeClosed(start, end)
|
||||
.parallel()
|
||||
.mapToObj(i -> i + suffix(i) + " ")
|
||||
.reduce(String::concat)
|
||||
.ifPresent(System.out::println)
|
||||
;
|
||||
}
|
||||
|
||||
public static void print(int[] startAndEnd) {
|
||||
print(startAndEnd[0], startAndEnd[1]);
|
||||
}
|
||||
|
||||
public static int[] startAndEnd(int start, int end) {
|
||||
return new int[] {
|
||||
start,
|
||||
end
|
||||
};
|
||||
}
|
||||
|
||||
public static void main(String... arguments){
|
||||
Stream.of(
|
||||
startAndEnd(0, 25),
|
||||
startAndEnd(250, 265),
|
||||
startAndEnd(1000, 1025)
|
||||
)
|
||||
.forEach(Nth::print)
|
||||
;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue