Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter units consumed: ");
int units = sc.nextInt();
double bill;
if (units <= 100) {
bill = units * 1.5;
} else if (units <= 200) {
bill = 100 * 1.5 + (units - 100) * 2.0;
} else {
bill = 100 * 1.5 + 100 * 2.0 + (units - 200) * 3.0;
}
System.out.println("Total bill = " + bill);
sc.close();
}
}Output
Enter units consumed: 250 Total bill = 500.0
We apply different per-unit rates depending on the slab the consumption falls into.