Created
November 24, 2012 07:32
-
-
Save sadah/4138794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (1..100).to_a.each_slice(15){|a| p a} を Java で書いてみたらこんなんになっちゃったんだけど。 | |
// これは僕のJava力が低下し過ぎているせいか…? | |
// この書き方だとListでも配列でもあんまりかわんない。 | |
// なんか、自分の書き方が間違ってる気がすごくするけど、かっこいいコードが思いつかなかった。 | |
import java.util.List; | |
import java.util.ArrayList; | |
public class A{ | |
public static void main(String args[]){ | |
List<Integer> ary = new ArrayList<Integer>(); | |
int max = 100; | |
for(int i = 0; i < max; i++){ | |
ary.add( i + 1 ); | |
} | |
int start = 0; | |
int sliceSize = 15; | |
while(start < max){ | |
int end = start + sliceSize; | |
if(end > max){ | |
end = max; | |
} | |
System.out.println(ary.subList( start , end )); | |
start += sliceSize; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment