Page 305 - IT-802_class_12
P. 305
bill_amount = (100 * 4.5)+(unit - 100) * 5.5;
else if(unit<=650)
bill_amount=(100 * 4.5)+(250 * 5.5)+(unit-350) * 7;
else
bill_amount=(100*4.5)+(250*5.5)+(300*7)+(unit-650)*9;
System.out.println("Bill amount = "+bill_amount);
}
}
Output:
Enter consumed unit :
258
Bill amount = 1319.0
25. To calculate the roots of a quadratic equation, write a program in Java. The Quadratic Formula employs the
letters "a," "b," and "c" from "ax + bx + c," where "a," "b," and "c" are simply numbers; these are the "numerical
2
coefficients" of the quadratic equation you must solve. For ax² + bx + c = 0, the value of x is given by:
− b 2 −b ± 4ac
x =
a 2
The following is the nature of the equation:
"Roots are imaginary" If the value of d is negative (d < 0).
"Roots are real and uneven" If the value of d is positive (d > 0).
"Roots are equivalent" If the value of d is zero (d = 0).
Ans. package com.mycompany.quadratic_equation;
import java.util.*;
public class Quadratic_equation
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of a");
int a = sc.nextint();
System.out.println("Enter the value of b");
int b = sc.nextint();
System.out.println("Enter the value of c");
int c = sc.nextint();
double d = math.sqrt(b * b - 4 * a * c);
double root1 = (-b + d) / (2 * a);
double root2 = (-b - d) / (2 * a);
if (d < 0)
System.out.println("Roots are imaginary");
if (d > 0)
Practical Work 303

