You are on page 1of 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 Asus
*/
public class AritmetickeOperacije {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println ("Primjeri Aritmetickih Operacija");
int i=50;
int j=i;
int k=j*2;
double l=k/6;
System.out.println
System.out.println
System.out.println
System.out.println
}
}

("i="+i);
("j="+j);
("k="+k);
("l="+l);

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 Asus
*/
public class Ifkomande {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int broj=10;
int mod=broj%2;
if (broj==0)
{
System.out.println ("Broj je nula");
}
else if (mod==0)
{
System.out.println("Broj je paran");
}
else
{
System.out.println("Broj je neparan");
}
}
}

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 dowhileprimjer;
/**
*
* @author Asus
*/
public class Dowhileprimjer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int i=0;
do
{

}
}

System.out.println("i je :"+i);
i++;

}
while (i<10);

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 java.util.*;
/**
*
* @author Asus
*/
public class Grananje {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner tastatura=new Scanner (System.in);
System.out.print("Unesite prvi broj:");
int broj1=tastatura.nextInt();
System.out.print("Unesite drugi
int broj2=tastatura.nextInt();
System.out.println();
if (broj1>broj2)
{
System.out.println(broj1+ "
}
else if (broj1<broj2)
{
System.out.println(broj1+ "
}
else
{
System.out.println(broj1+ "
}
}
}

broj:");

je vece od " +broj2);

je manje od " +broj2);

je jednak " +broj2);

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 Asus
*/
public class Factoriel {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int broj=3;
int faktorijel=broj;

}
}

for (int i=(broj -1); i>1;i--)


{
faktorijel=faktorijel*i;
}
System.out.println("faktorijel broja je:"+faktorijel);

6. Niz najveci i najmanji broj

/*
* 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 niz;
/**
*
* @author Asus
*/
public class Niz {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int brojevi[]=new int[] {2,6,9,14,21,30};
int najmanji=brojevi [0];
int najveci=brojevi[0];
for(int i=1;i<brojevi.length; i++)
{
if(brojevi[i]>najveci)
najveci=brojevi[i];
else if (brojevi[i]<najmanji)
najmanji=brojevi[i];
}
System.out.println("Najveci broj je:"+najveci);
System.out.println("Najmanji broj je:"+najmanji);
}
}

You might also like