You are on page 1of 4

Q 1: Write down a program that use 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;
public class bill {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

intunits ;
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);
}
}
Output

Figure 1

Q 2: Write a program that take two numbers from user and check whether
their sum is an even or odd number.

Output
import java.util.Scanner;

class Evenoddcheck

public static void main(String args[])

Scanner input = new Scanner (System.in);

System.out.print(“Input the first number: “);

int num1 = input.nextInt();


System.out.print(“Input the second number: “);

int num2 = input.nextInt();

int sum = num1 + num2;

if (sum % 2 == 0)

System.out.println(“The sum is even.”);

else

System.out.println(“The sum is odd.”);

Figure 2-

You might also like