Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zadatak 1. Pravougli trougao
- public class PravougliTrougao {
- public static void main(String args[])
- {
- double a, b, c;
- a = Double.parseDouble(args[0]);
- b = Double.parseDouble(args[1]);
- if (a>0 && b>0)
- {
- c = Math.sqrt(Math.pow(a, 2)+ Math.pow(b, 2));
- System.out.println(c);
- }
- else
- {
- System.out.println("Brojevi moraju biti pozitivni!");
- }
- }
- }
- Zadatak 2. Minimalni broj od 3 unesena
- import java.util.Scanner;
- public class MinOd3Broja {
- public static void main(String args[])
- {
- int a, b, c, min;
- Scanner scan = new Scanner(System.in);
- System.out.print("A = ");
- a = scan.nextInt();
- System.out.print("B = ");
- b = scan.nextInt();
- System.out.print("C = ");
- c = scan.nextInt();
- if (a>= 0 && b>= 0 && c>= 0)
- {
- min = a;
- if (b < min)
- min = b;
- if (c < min)
- min = c;
- System.out.println("Minimalni broj od ("+a+", "+b+", "+c+") = "+min);
- }
- else
- {
- System.out.println("Ne ispravne vrijednosti");
- }
- }
- }
- Zadatak 3. Najmanji broj u nizu brojeva
- import java.util.Scanner;
- public class NajmanjiBrojIzNiza {
- public static void main(String args[])
- {
- int niz[] = new int[10];
- //int niz[] = {1, 4, 5, 2, 6, 5, 6}; ---> Drugi nacin unosenja niza
- Scanner scan = new Scanner(System.in);
- for (int i = 0; i<=9; i++)
- {
- System.out.print(i+1+". broj = ");
- niz[i]= scan.nextInt();
- }
- int min = niz[0];
- for (int i = 0; i<=9; i++)
- {
- if (niz[i]<min)
- min = niz[i];
- }
- System.out.println("Najmanji broj je "+min);
- }
- }
- Zadatak 4. Sortiranje 3 broja
- import java.util.Scanner;
- public class Sortiranje {
- public static void main(String[] args)
- {
- int a, b, c, p;
- Scanner scan = new Scanner(System.in);
- System.out.print("A = ");
- a = scan.nextInt();
- System.out.print("B = ");
- b = scan.nextInt();
- System.out.print("C = ");
- c = scan.nextInt();
- if (a > b)
- {
- p = a;
- a = b;
- b = p;
- }
- if (a > c)
- {
- p = a;
- a = c;
- c = p;
- }
- if (b > c)
- {
- p = b;
- b = c;
- c = p;
- }
- System.out.println("A = "+a+", B = "+b+", C = "+c);
- }
- }
- Zadatak 5. Sortiranje brojeva iz liste
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Scanner;
- public class SortiranjePrekoListom {
- public static void main(String[] args)
- {
- ArrayList<Integer> lista = new ArrayList(); --> U < > zagradama navodimo tip podatka koji ce biti napisan u listi
- Scanner scan = new Scanner(System.in);
- int temp = 0;
- do
- {
- System.out.print(lista.size()+1+". broj = ");
- temp = scan.nextInt();
- if (temp != 0)
- lista.add(temp);
- else{
- System.out.println("Popunjavanje liste je zavrseno");
- }
- }
- while(temp != 0);
- System.out.println("ISPIS ELEMENATA LISTE!");
- for (int i = 0; i < lista.size();i++)
- System.out.println(lista.get(i));
- Comparator com = Collections.reverseOrder(); //Za sortiranje u opadajucem nizu
- Collections.sort(lista, com);//(lista) za sortiranje u rastucem
- System.out.println("2. nacin: ISPIS ELEMENATA LISTE POSLE SORTIRANJA!");
- for (int t : lista)
- {
- System.out.println(t);
- }
- }
- }
- Zadatak 6. Tabeliranje izraza
- import java.util.Scanner;
- public class TabeliranjeIzraza {
- public static void main(String[] args)
- {
- double xmin, xmax, dx, x, y;
- Scanner scan = new Scanner(System.in);
- System.out.print("xmin = ");
- xmin = scan.nextDouble();
- System.out.print("xmax = ");
- xmax = scan.nextDouble();
- System.out.print("dx = ");
- dx = scan.nextDouble();
- System.out.println("==========================");
- System.out.println("X \tY");
- for (x = xmin; x <= xmax; x+=dx)
- {
- y = (x*x*-2*x-2)/(x*x+1);
- System.out.println(x+"\t"+y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement