Taking inputs through command line arguments with an output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import java.util.*; class ComputeElectricityBill { public static void main(String args[]) { long units; units=Long.parseLong(args[0]); double billpay=0; if(units<100) billpay=units*1.20; else if(units<=300) billpay=100*1.20+(units-100)*2; else if(units>300) billpay=100*1.20+200*2+(units-300)*3; System.out.println("Bill to pay : " + billpay); } } |
output:
1 2 3 4 5 | C:\Users\goutham\Desktop\E>javac ComputeElectricityBill.java C:\Users\goutham\Desktop\E>java ComputeElectricityBill 500 Bill to pay : 1120.0 |