1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモ import java.util.Random;

Last updated at Posted at 2015-10-27

▪️


//import java.util.Random;はimport java.util.*;でもいい
//import java.util.*;にしてしまうとjava.utilの全てのクラスが
//読み込まれてしまうのでメモリ消費が多くなるので推薦しない
import java.util.Random;

public class test46 {
	static String name;
	static int hp = 50;
	final static int MAX_HP = 50;
        //static final int MAX_HP = 50;でもいい

	static int mp = 10;
	final static int MAX_MP = 10;

	public static void main(String[] args) {

		name = "ねこ";
		selfAid();
		pray(4);

	}

	// void→何も戻さない場合はvoidを指定する
	public static void selfAid() {
		System.out.println(name + "はセルフエイドを唱えた!");
		hp = MAX_HP;
		mp -= 5;

		System.out.println("HPが最大まで回復した。");

	}

	// 整数を戻す時はpublic int メソッド名
	public static int pray(int sec) {
		System.out.println(name + "は" + sec + "秒間天に祈った!");
		// Randomクラスをインスタンス化
		int recover = new Random().nextInt(3) + sec;
		int recoverActual = Math.min(MAX_MP - mp, recover);
		mp += recoverActual;
		System.out.println("MPが" + recoverActual + "回復した。");
		return recoverActual;

	}
}

▪️
ねこはセルフエイドを唱えた!
HPが最大まで回復した。
ねこは4秒間天に祈った!
MPが4回復した。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?