1.

WAP using scanner class to calculate the electricity bill based on the units entered by the user according to the following slab unit Cost per unit 0-100 5101-250 8>250 10

Answer»

ogram: import java.util.Scanner; PUBLIC class Main {    public static void main(STRING[] args) {        Scanner sc = new Scanner(System.in);        System.out.println("Enter the number of UNITS: ");        double n = sc.nextDouble();        if (n > 0) {            double bill = 0;            if (n <= 100) {                bill = n * 5;            } ELSE if (n > 100 && n <= 250) {                bill = n * 8;            } else if (n > 250) {                bill = n * 10;            }            long i = (long) n;            System.out.println("Total number of Units: " + i);            System.out.println("Total computed bill of " + i + " Units: " + bill);        }    } }



Discussion

No Comment Found