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);
}