Back To Java User Defined Methods Index
//program to create a function that computes discount based on price entered by the user (price is passed to function as integer argument , if price is greater than or equal to 1000, discount is calculated as 10 percent else 5 percent ) class cdiscount { public void calcdis(int price) { float discount; if(price>=1000) { discount=0.1f*price; } else { discount=0.05f*price; } System.out.println("discount is " + discount); } } public class calcdiscount { public static void main(String[] args) { cdiscount ob=new cdiscount(); ob.calcdis(2000); } }