Professional Documents
Culture Documents
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:");
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;
}
}
/*
* 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);
}
}