MOST Cise 7
Write a java
conditions;
to “alculate TOOK of y qu;
"atic equations
1S ae 4,
ir .
Roots Ate pe, O15; roots
eal and different
Toot], a “ira
~ R015 are ata,
al equal.
Toop, al
iid Roots are imaginary
import. J4va.utias,
import, Java. io,+,)
class qurdratic
(
double a,b,c,d, rq
TOO bsar OR
1X2;
scanner S=new SPsONEr (2¥stem. jny
system, out .PrintIn (Ente, Bebe values") ,
a=s.nextInt( );
pes-nextInt( );
ces.nextInt( );
d=b*b-4*a*c;
if(
{
system. out .print1n (™
rl=-c/b;
system. out. print1n ("The Toots is”
}
else
{
4£(d>0)
{
system. out.println (“The roots are
different”) ?
S(-btsqrt (d) )/ (2a);
*(-b-sart (dj) / (2#a);
The roots are linera roots
i
trl);
real §All
A “The fi ;
system. out.print1n( Tst root isn t
system. out.print1n (“The Second root isu, /
+r)
}
else .
{
if(d-=0)
{
system.out.print1n (“The roots are real e
qual”
rl=-b/(2*a) ;
system.out.println("The roots is” trl);
}
else
{
system.out.println("The roots are imaginary”)
iShit,
}
Exercise 12
Write a java program to find reverse of a given number
import java.util.*7
import java.io.*7
class reverse
{
public static void main
{
int num, d, rev=07
(String args[ })
Scanner s=new Scanner (System. in);
system. out.print1n ("Enter any number");
num=s.nextInt’ ( )7
while (num!=0)
{
d=num310;
rev=rev*10+d;
num=num/10;
}
System.out. println("The reverse of a given nue
is" +rev);
}
}
Compile and execute the above program as follows:
C:ava\jdk1.5\bin>javac Teverse.java
CNava\jdk1.5\bin>java reverse
1234
The reverse of a given number is4321
CNava\jdk1.5\bin>
Dvaraica 1%
}
| Enter any number
|Write a java program to display first ‘N’ number using do-whilelop
import java.util.*;
import java.io.*;
class numbers{ 7 ;
punt static void une
jnt nif
anne s=new Scanner (SYS
: “gut iprintin (“Babee n
stem
. pextint (oe
do
joe -pesnen crmamber:” +i)?
system
jeitti
cava\jdkl s\bin>}
clava\jdkl s\bin>j
fater n values
i
Number: 1
Number:2
Number:3
Sumber
Numbers 7]
Nonhers
Ca <
> dk S\bin>
ava numbers