0% found this document useful (0 votes)
17 views

java programs 1-10

The document contains multiple Java programming examples, including a Hello World program, arithmetic operations, and finding even or odd numbers. It also covers finding the greatest number, calculating the sum of numbers, and determining if a number is a palindrome. Each example includes code snippets and expected outputs.

Uploaded by

anime.shorts503
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

java programs 1-10

The document contains multiple Java programming examples, including a Hello World program, arithmetic operations, and finding even or odd numbers. It also covers finding the greatest number, calculating the sum of numbers, and determining if a number is a palindrome. Each example includes code snippets and expected outputs.

Uploaded by

anime.shorts503
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

rint hello lalotd,

alod.
1. n i t e a java ogam
public class Helloworld {

public StatiC voict main (Sting EI args)


System . outo pvintln ("elloy wora l, ")

Oudput:
Hello woel
perfoYm
2. hite a java pogrom all
aitmeti
opevation

packaqe arithme tie openNaios


import java util,*
piblic clas Amthne tie operatiog (
public 4tatic
void nalrn (Shing
int num1
int

int Sunn
int
dieene 2 nun 1

înt
proud 2

int
nm2
cliision
int
modules 2

Systen
1
Sum)
t difteNene);
Sysiem. out: println ("
proctue4 procut);
System.out printin (u
eiision
. out.
pinttn ("
division);
moclules t module)
3
Out pt:
produd: 1o0
clivision : 4
3.trile javo rograrr aver

odd
even.

packaqe evenodd;
Impov t java.util.Sa
java.util."Scanner;
ublic class Evenodcd
public static vold main ( sting I3 args)
ScanneN SC = new
Seanner (Systemiin)
Systen .oute println C"Ente a nunmber?;
int numbe = SC. net Lnt (),

Systeot: pintln(nunmbert even)


3 else f

Sys1ern.Out pintln Cnunber t odd ").


c. close ())

3
Output:
Erter
number24
24 1s
even.
Ente a nunbey
ite java mograrn tind
nunbs

pacleage qreateH nmnber


import jwa. util, Scanne:
public clas
Greertest nunber f
public Static
void maln Csting
C1arg
Sconner new
Scounnex CSystem.in);
Sys1e0ud pint ln C Erter ist nunber : ) ;
int 2 Se.netInte)

System,out pint ln(" Erter Second nunnber? )


întt nun 2 Se. net Int ()

Systen.oudintln (" Errter thid number i),


int nunz Se. ne Înt O

int gYeoriest num 1

3Yeaclest

4 (num qreetest ){
SYelest nun 3;
3

Sysiern. oule intln C The


reotest
nenberS

gyeale st);
Sc. close (y,

Output:
Enter finst nunber 4

12

Ender econd nmbe


48

Enter thir nunbe


464.
The g ertest

464
5. ite a ova progmarn to find e

nembeos

package Sumofn;
impor t jowo. uLil. Scoanner:
publie

public Stotic void main (sting


Seanner . se o new Scanner (systemin
nt S m

System.out. intin( Erlerx the olue ot n:):


int n SC«netInt())
int um o

fov ( intiz 1 i<n; itt)

System.out pintln ("The nt

+ Sum)

Sc. close c

Eiey
The Snn e4 ins nLimbens is 15.
nlite
java pogam
given
packoge qed;
impey t java. util Scanner
publie clas Gcd
public Statl c void mainl sting I arg)
Scannex
Scanner (Sycten. in);
System-ot: pintm(" Erter the fint nmber
int nun 1 = 1c. net Int()

Syste.ot pintin( Ente the (econl number;


int nuum2 sc, netInt ()

int acd ind GCD(


nun1,nunm);
System.ot pint InCM The
and

ged);
Sc. close C
3
public
int
ind Geo(int num, int
num 2) {

3
etunno lnd
GcD(nwn2,nun |.
num2)!
3
3

Erter 4irst nuunber 5o


Ente
Seunl nunbeN
The
and
a
java progam
numbes upto nunhes
odd and even

packaqe Sum ofodcd and euen numbe ;


import java.util. Scannen ;
puslic clars Sumo oddand even nunnbes

public statie void maln (sting CJavg) (


= new SeannerC Sys1e.in))

System. out pintlntEnie the value of


Int n Scnet It()}
int Sum Even
Înt

for C int i: 1
;i=;it t)
o) {
SumEver t =i
else

SumOdd: t = i
3

Systemn-out pnntln (The Sunt


t Sum Even)) evennumbeS
Sc.close

Opec:
Entex the value
Sun
even nunbens: 30
Sun Odc
unnbes : 25.
8. Wie java progranm pint the follbw
Symbol :

package patern of ymbols !


puslfe clasi
public
pattevnofybols f
public State void

*** ** );
System. out. pintln( *

System. butphntln ( 4
System.out println cu

Systemout.pinttn (*
3

Oudpud:
Sum) t
Suno TheThe print
In
(" Sycten.0uct-
nunbeN
digit -Sum
digit int
(nmber
o)13 while
nunber.} nunnber Oiginal înt
2
Sun înt
netLatC SC. nunnbex nb
2
Enter
a
Systemin)) Seanner Scanner
SC
mein Voicl public
unnbersf iven Sumot clau public
util.* jawa, Tmport
vennumbes; Sumetgi package
numser qiven cdigits
in
-ne
mcam java nride 4.
Output:
Entev a ninben: I2 3

The Sum of 23 is
I0. arite a
java prg pmnt the
numbe of Dalindom Y not
package Palindyome inbe
inport jova-util.;
publtc cias Palinchme {

public Static

ScanneY de new
Scanne(System.in)
Sysierm.out. pint In( " enter nuner:)
int SCnect Int C);

T+ ( palincorme cnurmbe))
System. ot. printnC" The qiven nber is a
palincione numben.");

Systemnsol. pntln C* The qven nunben îs not a

palincome number.");

boolean
public Statie to n palindveme (int nmtbe)

int vevesednumbes O;
int oiginanumtbe numbes
while (nunbe : o) {
int diqit numbe
nevensednumber
YeNerrsednunnber
num berx digit;
3
etusn Oriqinalnumber =
Nevenseclnumber )

3
3

Output:
enteN
nnbe
212
the qiven numbeN is

enlen
palindvome imbex.
nnbe
221.
the
given ninbe îs not
palindvome.
neembey.

You might also like