0
0

More than 3 years have passed since last update.

Logic忘備録_if_return

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