Page 304 - IT-802_class_12
P. 304
while (g>=1)
{
if(a%g==0 && b%g==0)
{
break;
}
g--;
}
l=(a*b)/g;
System.out.println("GCD of "+ a +" and "+ b +" is "+ g);
System.out.println("LCm of "+ a +" and "+ b +" is "+ l);
}
}
Ans. Enter two numbers:
4
64
GCD of 4 and 64 is 4
LCM of 4 and 64 is 64
24. The following are the bill payment charges of the ABC Company:
Units of electricity Rate per unit
First 100 units 4.5 per unit
next 250 units 5.5 per unit
next 300 units 7 per unit
above 650 units 9 per unit
Write a Java program to input the units of the electricity consumed by the customer and display the amount to be paid
by the customer.
Ans. package com.mycompany.elec_bill;
import java.util.*;
class Elec_bill
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
int unit;
double bill_amount;
System.out.println("Enter consumed unit : ");
unit=sc.nextint();
if(unit <= 100)
bill_amount = unit * 4.5;
else if(unit <= 350)
Touchpad Information Technology-XI-XII
302 T ouchpad In f orma tion T echnology

