java Exercise-1
java Exercise-1
import java.io.*;
class DefaultValues
static byte b;
static short s;
static int i;
static long l;
static float f;
static double d;
static char c;
Output:
The default values of primitive data types are:
AIM: To write a java program that display the roots of a quadratic equation ax2+bx=0.
Calculate the discriminate D and basing on value of D, describe the nature of root.
import java.util.*;
class quadraticdemo
int a, b, c;
System.out.print("Enter a:");
a = s.nextInt();
System.out.print("Enter b:");
b = s.nextInt();
System.out.print("Enter c:");
c = s.nextInt();
D = b * b - 4 * a * c;
if(D > 0)
r1 = ( - b + Math.sqrt(D))/(2*a);
r2 = (-b - Math.sqrt(D))/(2*a);
else if(D == 0)
r1 = (-b+Math.sqrt(D))/(2*a);
System.out.println("Root:"+r1);
else
Output:
Enter a:2
Enter b:3
Enter c:1