Computer Science, asked by joshuathomas113645, 2 months ago

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 5

101-250 8

>250 10

Answers

Answered by atrs7391
1

Your Program:

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);

       }

   }

}

Similar questions