Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Last active October 6, 2016 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/d114366d2ccb3bcd7e22298ff9b19e36 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/d114366d2ccb3bcd7e22298ff9b19e36 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習2-8
import java.util.Random;
import java.util.Scanner;
public class En2_8 {
public static void main(String[] args) {
Random rand = new Random();
Scanner stdIn = new Scanner(System.in);
System.out.print("整数値:");
int seisu = stdIn.nextInt();
//-5~5までの乱数を生成。
int ransu = rand.nextInt(11) - 5;
System.out.print("その値の±5の乱数を生成しました。");
System.out.print("それは" + (seisu + ransu) + "です。");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment