0
0

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.

Logic忘備録_if_return

0
Posted at

ifがtrueになったら処理を返す(returnによって計算処理を中断して戻ることができる。)

IfReturn.java
public static void main(String[] args) {
		calculatePrice(3,100);
		System.out.println("計算の終わり");
		calculatePrice(-1,200);
		System.out.println("計算の終わり");

	}
	private static void calculatePrice(int number, int price) {
		if(number < 0) {
			System.out.println("個数の数値:"+number+"がマイナスです");
			return;//ここで処理を終わらせて処理を返している
		}
		System.out.println("果物1つの値段:" + price/number);
	}
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?