Skip to content

Instantly share code, notes, and snippets.

@shikajiro
Created July 18, 2013 14:44
Show Gist options
  • Save shikajiro/6029916 to your computer and use it in GitHub Desktop.
Save shikajiro/6029916 to your computer and use it in GitHub Desktop.
long型の10個の配列に0から100までのランダムな値を入れてください。 それら中から、3で割り切れる数値または5で割り切れる数値だけを画面に表示してください。
import java.util.Random;
public class HomeWork {
public static void main(String[] args) {
long[] numbers = new long[10];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = new Random().nextInt(101);
}
for (long l : numbers) {
if (l % 3 == 0 || l % 5 == 0) {
System.out.println(l);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment