티스토리 뷰

package asser;

public class Product {
	public double applyDiscount(double price) {
		assert(price>0);
		return price*0.50;
	}
	public static void main(String[] args) {
		Product p=new Product();
		double newPrice=p.applyDiscount(Double.parseDouble(args[0]));
		System.out.println("New Price: "+newPrice);
	}
}

 


the command: java Product 0
What is the result?

출력:
New Price: 0.0

해설:
the command haven't -ea

즉 자바 실행 시 -ea 옵션을 넣지 않았기 때문에 assertion이 적용되지 않는다.

문제에서 java Product 0 으로 되어 있다.

참고로 -ea 의미는 enable assertion 이라는 뜻이다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함