Java Notes
Java Notes
int
Tes.
32 bits
byte No integers stofed- 28
Shor t 16
bts
\ona 64 bjts
Range to
(Unsigned)
-126tot 127
inti= I0
byle 130
- 126
Aprecision D7 16 plecisionDT
CABSnT-30o1
Flonting /
Point Red Numbers Daa Types
the
Numters. haring pot
Rxressedwith
rationa
hele a decimal points
primitive data, types Float Dovble
) Float
Single(iecision data tyee (S2e
= 32 bits)
Decimal point prcisions q diglts
) Doule-
Double precision doto tyge( e1ze 6u bits)
Decimalpoint prectšton =I6 digits
Char
t an store onlyaSngle chatactef
Boolen
trve Lalse
It cn haye 2, valves
rins
•.H is
a seayuence o
chargters. non-pimitive
data type to trmg
stoíe character. tings.
S.
cdass
actuallya
Operators -
special
Opesatos aresecial enbols that Rro1m
operateions on 4,2, 9 3 0perOnd
Arithmetc Operators -
System ovt
prittnCNomei Aean "
Sout ( Addíess:
Sout ( Mob:
so0tCEM ail?mo{on@gail
usu2305")
com
o
codebased on whethey a|ven ccndihn
expiession Is tye ofilsSe
CCondition ) cond ition elher evaly
1/ Code to ttue oY
alse
blok
Ese Bcck
evalvate
Not neCessary
to lalse
Executes icondition
Re laional Operotors
double dbl =
SC.
String woTd
netOouble C);
Sc.next)
Siring lonstin=
- Input 3
num,cslulote
import
avauHl.Scanner;
main )
s new scanner (Sysiem.in)
Jouble
sout C
x,Y2
Enter numb js :
ba-b
main ()
Scanner. SC new Scqnner (Sy shem.n
Sout Enter 2 number s ")
O
b= a-b
Compaíe
main()
Scanner (Sy steen.in)
Scanner Sc_ne
Sout Entet
int
SC
netntC))
int
b se. nest Int C)
Sout(s
A\s. bigger")
3
elie
Sout( ßoh ae eaval
Soutl Even")
else
ogital Opesatozs
tapes NOT
190
6 and
I Check'l a is
mber iS divisble by
NOT diwistble by S
=>mt. O)
(humo 6=
Sout(Yes")
else
Sout ( No ");
/ Check i an yeot
Heor leae
Yes
-tse
SouttNO "}
int 4
=O
Sou (" Ye");
3
else
Sout C
NO))
ind hether it is tve,e or
no. ")
else i Cumo){
out (Rositive
3 no,)
else
3
Sout Negaiye no);
Int. day Si
iCday )
c6
else
Sot Invalid input)
Given the
marksint its erade
80-89 At
A
else
int
else
Sout A+ ");
3
else
Sout (A);
(morK)=6o marks= 69)
else
Sout &")
marks<= S9)
Sout ( );}:
else S oUt (
int num= 30
Jo 6 = 0)
sou
Yes"),
else
)
Alternale way>
nom
/6=O)
o
Yes")
else
2
(aiven s
DUbers,hek vhish isigest
Sout X
is the bigAes) ?
else
7 is the
bih est)
else
Sout Y
is the
ese Sout * Z
iges)
;
3
is the bigest ")
feql distinct
4
ools are
Veol but Sone
imagina
int
do int D
else
Roots ose
sout
4
int doy
switch Cday)
break
I/ hivenno a
month, print coresfnd ing month nane
Sconner sc =
new Sconner
Sysiemin)
SoutEnter a
monh numberi
nl mon
Suith mon)
bíeaky
ase1 Sout ( Feh")
bfeak',
Cse 3:Sot ( narch );
bienk
bíegky
bresk
Cose 6
case' 7
case'
Suteh keywod
condiiong
l test some vaiable lorese of
oY
Cases) and per lorm. tasks
test ondihons, we ve Swlteh keyword
A
is cimilar to, Iaadder i stetemenis
is
The aiesene b/w suitch Amdi
while Swikh vSeshe
VSe dielent vatiabler
Some yatigble. bYeak'
Another dill erence Switch reuirer
is
Statement
Loopsin aa
i Do wile Ioop
i) for each loop(prim orly use d for obj ets)
x 1 (2*1)
Sout (2
Sout ( *
2x2 (2*2));
(1*3))
Sout 2 x (2r4))
Sout 2xS (2*6));
31
32
64
int ch
il=Nit=1)
Soutnum)
3 pa
22
multiplicotion tolb le
Scomner Sc
mey_Scanner (System
Sout Enter in)
intnum sc. metInt);
1
Ror(int i= it=1){
SOutnum
J| Series SUn
int
lorCint. i 1
it )
SUm
=
Ses ies Sym):
{orcint i= mnum
i=1
goct
1
2) 2)S 2
lo
nt bin O.
$iing
for tint
While (n>o)
d
int
= +
bin (bin o) dj
3
=
sou\ CBinaiy umber
6
S
2.8
CALSnI-30o.
nt num =3us6
int
SUm = O
Sum
a
I/ Reverse nymber
int 3456.
Strina s-"
or
(int i nun0
mum fev)
Sout ( ReNeise
=
SoutCReverse
Prit odd
orin i=1
3
3) 2
S2.
it=|)
SoutCS;
Rrint nmbers
not s
and 7 oml to whose
Lsdi
os Cint
il ikiooi )
Sout ();
Cint i 1
is=ny m
it=)
3 COUnttt,
soyt Facto S
COvnt)
6
3s.r 2
==0)
{factosSout ( Prine" )
else
Sovt (NGt Pine"):
3
Alteinatve
fo Cint i2iSE Matha
sat (oum);iti)
fators
Cnm
i<smoth. Sat(num)it)
breok
3
forter icisRrine)
sout ( Prime
else
9
6
Sout NotRine"
IPint prime numbeis fom
Ror (int
nUm=2; nym lo0 numt)
boolen isrime
=
true
af (inti= 2iK= Malh. Soyrt(num) it=){
isPrime galse,
break'
Sout (i)
o
To 1ün a set. iohe hends sefestedly far ixed
ho:
Basic uchuse is
wbie loop
Used when
(ondiion is
we
trUQ
nont to loop s long
sn gyen
Tt
is usedwhen
we do not know heorehand
how man
hmes the looe will YUn.
-
.A checks
he condithsn irst bejofe exeeuhing
ts code
blok,
o-while loop
,Similo to
while loop.
- The
koop
\ exe quled at least once
aonditgn, is checked ond then he
- I4
is
Used or meny
based progiamming
( breok' Statemem
T
is vsed to jvmp ovt
ol the \oop
immedinely mext stalement onto he
ofier it
Continue stalement
Aike bYeak,
ontinue statement also
cuYrent o
indersupls the
low he proiQm T
skies he
semainins code al1er it ond jumps
Herotion
to next the
he IooR
tings in Iava
Stin S2 new
gCA")
Shrin
Sting o
class In Jayq,TH hos
inbult {un Hons.
SOut
S1.lensth))}
Sot (s1. chorfAiC)
characterot inae ti
SL.Compaie Tols2)
a
Shring S
seauente choraters
class
s
Sych lengthh At(1
6 6-9!
32 A723S
48-570igit
13 o)
StrinnesirStrlconcat (6t2)
sout(wSh)
Checkshings are
esjual.
Soutye");
else
SoutNO")
/Aevese String
Gting
int ze =
tr. length)
= Str. to Char ArrayO
chor C
o1
AFFAN
912e S
FFAA
NAFFA
nRevesse string
String
(orCint
K=f+ Str. hor AL)
Sout (e Rever se
AlternatiNe
er' -)
lorCint i0 Y
isie ) it )
St, Char AtCi)
public sontic boolean islar (Sthing str)
int sSize strlength0;
Sting
or Cint it size-I,i)o,i-)
14Str, chof Ati)
R(st. equalsr))
Neturn trve
Ietin alse ,
else
Sout ( NOT Pa\indíome")}
AFFA
NEF AA
AFA
CABSM-300|L
palindTome
Or.not
I/Checkwheher_o gien stingis
boolean islal trves
String str AecOCBA")
=
int sìZe str leng thO
lorlint i -0; ika(lze /2) it)
beclean iPal>ne
char str. char At())
cha b sr charAt(Si2e -i-)
isPal=alse
bíeak
Gcta)
Saut ( Palindsone "):
Selse
indrome
poa
Sout ( Noto
u
Students S7,6 9, 15, 67
Calculate the average
dovble =Um/Cdoube)count
double av
Cathtc+d)4.0
Fnd the larset number
Soutla)
else
Rendita en stnag
lof Cimt
i0ierr <alengh it)
CilF SC. net
Int();
bgfe &bt
double
Mew double l5j
Sconner SC new Scanner C Sy stem in)
orldouble i ar)
Sout(i
atray lements
I/ Sum r al
int new int Lio;
sc ( System n)
PortinScanner newScönner
or Cint
i0
Sovi ( Enter elem ent
+
i+)
3
to Cint eL: o)
Sout Su m =
sum
Sout ( Same"):
else
sout (otdi eient),
la elements
int Size= aT.lenth
temp
| Cavnt odd
and
=
even in an ar
int COUnte ,
intC] SIY =Li,23y, :3
Rorlint eli TY)
CoUntett
else
coUnt-O tt)
Sovt count~e)
Sout Ccount-,
MOximum element an aray
/Flnd
int max ar Co3;
Jor Cinte arr)?
3
int C] atr=S6 78 45, 343)
Ant min
lorCint ei arr)
e
min