View
222
Download
0
Category
Preview:
Citation preview
7/23/2019 Vjezbe 15.12.2014
http://slidepdf.com/reader/full/vjezbe-15122014 1/6
1. Aritmeticke operacije
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aritmetickeoperacije;
/**
*
* @author sus
*/
pu!lic class ritmeticke"peracije #
/**
* @param args the command line arguments
*/
pu!lic static $oid main%&tring'( args) #
&stem.out.println %+Primjeri ritmetickih "peracija+);
int i-;
int ji;
int kj*;
dou!le lk/0;
&stem.out.println %+i+1i);
&stem.out.println %+j+1j);
&stem.out.println %+k+1k);
&stem.out.println %+l+1l);
2
2
7/23/2019 Vjezbe 15.12.2014
http://slidepdf.com/reader/full/vjezbe-15122014 2/6
2. IF petlja
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ifkomande;
/**
*
* @author sus
*/
pu!lic class 3fkomande #
/**
* @param args the command line arguments
*/
pu!lic static $oid main%&tring'( args) #
int !roj4;
int mod!roj5;
if %!roj)
#
&stem.out.println %+6roj je nula+);
2
else if %mod)
#
&stem.out.println%+6roj je paran+);
2
else
#
&stem.out.println%+6roj je neparan+);
2
2
2
7/23/2019 Vjezbe 15.12.2014
http://slidepdf.com/reader/full/vjezbe-15122014 3/6
3. Do-While petlja
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package do7hileprimjer;
/**
*
* @author sus
*/
pu!lic class 8o7hileprimjer #
/**
* @param args the command line arguments
*/
pu!lic static $oid main%&tring'( args) #
int i;
do
#
&stem.out.println%+i je 9+1i);
i11;
2
7hile %i:4);
2
2
7/23/2019 Vjezbe 15.12.2014
http://slidepdf.com/reader/full/vjezbe-15122014 4/6
4. Grananje
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grananje;
import ja$a.util.*;
/**
*
* @author sus
*/
pu!lic class rananje #
/**
* @param args the command line arguments
*/
pu!lic static $oid main%&tring'( args) #
&canner tastaturane7 &canner %&stem.in);
&stem.out.print%+<nesite pr$i !roj9+);
int !roj4tastatura.ne=t3nt%);
&stem.out.print%+<nesite drugi !roj9+);
int !rojtastatura.ne=t3nt%);
&stem.out.println%);
if %!roj4>!roj)
#
&stem.out.println%!roj41 + je $ece od + 1!roj);
2
else if %!roj4:!roj)
#
&stem.out.println%!roj41 + je manje od + 1!roj);
2
else
#
&stem.out.println%!roj41 + je jednak + 1!roj);
2
2 2
7/23/2019 Vjezbe 15.12.2014
http://slidepdf.com/reader/full/vjezbe-15122014 5/6
5. Faktorijel
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package factoriel;
/**
*
* @author sus
*/
pu!lic class ?actoriel #
/**
* @param args the command line arguments
*/
pu!lic static $oid main%&tring'( args) #
int !roj;
int faktorijel!roj;
for %int i%!roj A4); i>4;iAA)
#
faktorijelfaktorijel*i;
2
&stem.out.println%+faktorijel !roja je9+1faktorijel);
2
2
7/23/2019 Vjezbe 15.12.2014
http://slidepdf.com/reader/full/vjezbe-15122014 6/6
6. Niz naj!eci i najmanji "roj
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package niB;
/**
*
* @author sus
*/
pu!lic class CiB #
/**
* @param args the command line arguments
*/
pu!lic static $oid main%&tring'( args) #
int !roje$i'(ne7 int'( #,0,D,4E,4,2;
int najmanji!roje$i '(;
int naj$eci!roje$i'(;
for%int i4;i:!roje$i.length; i11)
#
if%!roje$i'i(>naj$eci)
naj$eci!roje$i'i(;
else if %!roje$i'i(:najmanji)
najmanji!roje$i'i(;
2
&stem.out.println%+Caj$eci !roj je9+1naj$eci);
&stem.out.println%+Cajmanji !roj je9+1najmanji);
2
2
Recommended