1.
Make the use of Logical Operators
<?php
$a = true; $b =
false;
echo ($a && $b) ? "Both are true\n" : "At least one is false\n";
echo ($a || $b) ? "At least one is true\n" : "Both are false\n";
echo (!$a) ? "a is false\n" : "a is true\n";
echo ($a xor $b) ? "Only one is true\n" : "Both are either true or false\n"; ?>
Output:
At least one is false At least
one is true a is true Only
one is true
2. Check number is Positive or Negative
<?php
$number = -5;
if ($number > 0)
{
echo "$number is Positive";
}
elseif ($number < 0)
{
echo "$number is Negative";
}
else
{
echo "The number is Zero";
}
?>
Output:
-5 is Negative
3. Convert 0-9 Number to Words using switch statement
<?php $number
= 3;
switch ($number)
{
case 0: echo "Zero"; break; case 1:
echo "One"; break; case 2: echo "Two";
break; case 3: echo "Three"; break;
case 4: echo "Four"; break; case 5:
echo "Five"; break; case 6: echo "Six";
break; case 7: echo "Seven"; break;
case 8: echo "Eight"; break; case 9:
echo "Nine"; break; default: echo
"Invalid number"; }
?>
Output:
Three
4. Find Largest Number from three number using if else statement.
<?php
$a = 25;
$b = 40; $c =
30;
if ($a >= $b && $a >= $c)
{
echo "$a is the largest";
}
elseif ($b >= $a && $b >= $c)
{
echo "$b is the largest"
}
else
{
echo "$c is the largest";
}
?>
Output:
40 is the largest
5. Write a java program to input electricity unit charges and calculate total Electricity Bill
according to the given condition:
for first 50 unit Rs.0.50/unit
for next 100 unit Rs.0.75/unit
for next 100 unit Rs.1.20/unit
for unit above 2.50 Rs.1.50/unit
An additional subcharge of 20% is added to the bill
import [Link];
public class ElectricityBill
public static void main(String[] args)
Scanner sc = new Scanner([Link]);
[Link]("Enter electricity units consumed: ");
int units = [Link]();
double bill = 0;
if (units <= 50)
bill = units * 0.50;
else if (units <= 150)
bill = 50 * 0.50 + (units - 50) * 0.75;
else if (units <= 250)
{
bill = 50 * 0.50 + 100 * 0.75 + (units - 150) * 1.20;
else
bill = 50 * 0.50 + 100 * 0.75 + 100 * 1.20 + (units - 250) * 1.50;
bill += bill * 0.20;
[Link]("Total Electricity Bill: Rs. " + bill); [Link]();
}
}
Output:
Enter electricity units consumed: 300
Total Electricity Bill: Rs. 420.0