Created
October 7, 2016 13:34
-
-
Save mokomokohitsuzi/e6d5ee13a7375ce9c2f6b144d4206e20 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習2-9
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
import java.util.Random; | |
public class En2_9 { | |
public static void main(String[] args) { | |
Random rand = new Random(); | |
// (1)実数値でのランダム生成 | |
double jisu = rand.nextDouble(); | |
// (2)整数値で0~9をのランダム生成 | |
int seisu = rand.nextInt(10); | |
// (3)整数値で0~1をランダム生成 | |
int seisu2 = rand.nextInt(2); | |
// 出力 | |
System.out.println("0.0以上1.0未満の実数値をランダムに生成して表示: " + jisu); | |
System.out.println(); | |
// (1)+(2)にて作成。 | |
System.out.println("0.0以上10.0未満の実数値をランダムに生成して表示: " + (seisu + jisu)); | |
System.out.println(); | |
// (1)+(3)にて作成。※(3)を反転することで-1~0を作成する。 | |
System.out.println("-1.0以上1.0未満の実数値をランダムに生成して表示: " + (-seisu2 + jisu)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment