TECH PIXEL

"Tech Pixel": Clearly mentions the site name. "Your go-to source for the latest tech news, reviews, and tutorials": Summarizes what the site offers. "Stay updated with the newest trends in technology": Highlights the value of staying current with tech trends. "Enhance your skills with our expert guides": Emphasizes the practical benefits and expertise available on the site.

program in java calculate electricity bill with the help of charges.

 

Q1:  Write down a  program that uses Electricity Function to calculate the electricity bill with the help of the below charges:                                                                                                                                                  

1 to 100 units –    Rs.5

101 to 200 units – Rs.7

202 to 300 units – Rs.10

above 300 units – Rs.15

 

import java.util.Scanner;

 

/**

 *

 * @author Hasssan

 */

public class Mahhnoor3 {

 

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        

     int units ;

double amount;

Scanner scan=new Scanner(System.in);

System.out.print("Enter number of unit you consumed: ");

units=scan.nextInt();//taking input from user for usage unit

if(1>=units && units<=100){

    amount=(units*5);

}

else if(units>=101 && units<=200){

    amount=((100*5)+(units-100)*7);

}

else if (units>=201 && units<=300){

      amount=((100*5)+(100*7)+(units-200)*10);

}

else if(units>300){

      amount=((100*5)+(100*7)+(100*10)+(units-300)*15);

}

else{

      amount=0;

}

System.out.print("Total amount is: "+amount);

}

}

2nd:

ublic class Mahhnoor3 {

 

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

      

    // TODO Auto-generated method stub

 

    System.out.print("Enter number so it could be added: ");

    Scanner input = new Scanner(System.in);

 

    int sum = 0;

    int num = input.nextInt();

 

    while (num > 0){

        int digit = num % 10;

        num /= 10;

        sum += digit;

 

    }

    if (sum % 2 ==0){

                System.out.println("Even");

            }

            else{

                System.out.println("Odd");

            }

            System.out.println("The Sum of the digits is: " + sum);

          



Post a Comment

0 Comments