Created
October 5, 2016 12:27
-
-
Save mokomokohitsuzi/df6780d9d79e0ba33b3f1bb2aaceec53 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習2-7
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_7 { | |
public static void main(String[] args) { | |
// 乱数読み込み | |
Random rand = new Random(); | |
// 0~8までの乱数作成し、それに+1する。 | |
int ransu1 = rand.nextInt(9) + 1; | |
// 結果を出力 | |
System.out.println(" 1~9までの乱数を生成:"+ransu1); | |
System.out.println(); | |
// 0~8までの乱数作成し、それに+1する。 | |
int ransu2 = rand.nextInt(9) + 1; | |
// 結果を出力する際にマイナスをかける。 | |
System.out.println("-1~-9までの乱数を生成:"+-ransu2); | |
System.out.println(); | |
// 0~89までの乱数作成し、それに+10する。 | |
int ransu3 = rand.nextInt(90) + 10; | |
// 結果を出力 | |
System.out.println("10~99までの乱数を生成:"+ransu3); | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment