Advertisement
VIKTOR21

programiranje vjeybe 2

Oct 23rd, 2015
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. public class trougao
  2. {
  3.  
  4.  
  5. public static void main(String args[])
  6. {
  7. double a,b,c;
  8.  
  9. a = Double.parseDouble(args[0]);
  10. b = Double.parseDouble(args[1]);
  11.  
  12.  
  13. if(a>0 && b>0)
  14. {
  15. c = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2));
  16. System.out.println("a = "+a+ "\nb = "+b+"\nc = "+c);
  17.  
  18. }
  19. else
  20. {
  21. System.out.println("negativne vrijednosti");
  22. }
  23.  
  24. }
  25.  
  26. }
  27.  
  28.  
  29.  
  30. import java.util.*;
  31. public class zadatak2
  32. {
  33.  
  34. public static void main(String[] args)
  35. {
  36. int a, b, c, min;
  37. boolean provera = false;
  38.  
  39. Scanner scan = new Scanner(System.in); // upis sa tastature
  40. do{
  41. System.out.print("a = ");
  42. a = scan.nextInt();
  43.  
  44. System.out.print("b = ");
  45. b = scan.nextInt();
  46.  
  47. System.out.print("c = ");
  48. c = scan.nextInt();
  49.  
  50. if(a >= 0 && b >= 0 && c >= 0)
  51. {
  52. provera = false;
  53. min = a;
  54.  
  55. if (b<a) min = b;
  56. if (c<a) min = c;
  57.  
  58. System.out.println("min("+a+", "+b+", "+c+") = "+min);
  59. }else
  60. {
  61. provera = true;
  62. System.out.println("Neispravne vrijednosti");
  63. }
  64. }while(provera);
  65.  
  66. }
  67.  
  68. }
  69.  
  70. import java.util.Scanner;
  71.  
  72.  
  73. public class zadatak3
  74. {
  75.  
  76.  
  77. public static void main(String[] args)
  78. {
  79. int niz[]= new int[10]; //pravi niz od 10 integera
  80. //int niz2[] = [1, 2, 3, 4, 5, 6, 7];
  81.  
  82. Scanner scan = new Scanner(System.in);
  83.  
  84. for (int i = 0; i<10; i++)
  85. {
  86. System.out.print(i+1+". broj = ");
  87. niz[i]= scan.nextInt();
  88. }
  89.  
  90. int min=niz[0];
  91.  
  92. for (int i = 0; i< 10; i++)
  93. {
  94. if (niz[i]< min ) min = niz[i];
  95. }
  96. System.out.print("Najmanji broj je "+ min);
  97.  
  98. }
  99.  
  100. }
  101.  
  102.  
  103.  
  104. import java.util.Scanner;
  105.  
  106.  
  107. public class zadatak3
  108. {
  109.  
  110.  
  111. public static void main(String[] args)
  112. {
  113. int niz[]= new int[10]; //pravi niz od 10 integera
  114. //int niz2[] = [1, 2, 3, 4, 5, 6, 7];
  115.  
  116. Scanner scan = new Scanner(System.in);
  117.  
  118. int min=0;
  119. for (int i = 0; i<10; i++)
  120. {
  121. System.out.print(i+1+". broj = ");
  122. niz[i]= scan.nextInt();
  123. if(i == 0)
  124. {
  125. min = niz[i];
  126. }else{
  127. if (niz[i] < min ) min = niz[i];
  128. }
  129. }
  130.  
  131. System.out.print("Najmanji broj je "+ min);
  132.  
  133. }
  134.  
  135. }
  136.  
  137.  
  138. import java.util.Scanner;
  139.  
  140.  
  141. public class zadatak4
  142. {
  143.  
  144.  
  145. public static void main(String[] args)
  146. {
  147. int a,b,c,pom;
  148. Scanner scan = new Scanner(System.in);
  149.  
  150. System.out.print("a = ");
  151. a = scan.nextInt();
  152.  
  153. System.out.print("b = ");
  154. b = scan.nextInt();
  155.  
  156. System.out.print("c = ");
  157. c = scan.nextInt();
  158.  
  159. if(a > b) // poredimo 1. i 2.
  160. {
  161. pom = a; a = b; b = pom;
  162. }
  163. if (a>c) // poredimo 1. i 3.
  164. {
  165. pom = a; a = c; c = pom;
  166. }
  167. if (b>c) // poredimo 2. i 3.
  168. {
  169. pom = b; b = c; c = pom;
  170. }
  171.  
  172. System.out.println("Uredjeno: "+a+", "+b+", "+c);
  173.  
  174. }
  175.  
  176. }
  177.  
  178. import java.util.*;
  179.  
  180. public class Zadatak5
  181. {
  182.  
  183.  
  184. public static void main(String[] args)
  185. {
  186. ArrayList<Integer> lista = new ArrayList();
  187.  
  188. Scanner scan = new Scanner(System.in);
  189. int temp = 0;
  190. do{
  191. System.out.print(lista.size()+1+". broj =");
  192. temp = scan.nextInt();
  193. if(temp != 0 )
  194. lista.add(temp);
  195. else
  196. System.out.println("-- kraj");
  197. }while(temp != 0 );
  198.  
  199. System.out.println("1. nacin ispisa el liste");
  200. for(int i = 0; i < lista.size(); i++)
  201. {
  202. System.out.println(lista.get(i));
  203. }
  204. Comparator com = Collections.reverseOrder();
  205. Collections.sort(lista, com);
  206.  
  207.  
  208. System.out.println("2. nacin ispisa el liste");
  209. for(int t : lista)
  210. {
  211. System.out.println(t);
  212. }
  213. System.out.println("MAX = "+Collections.max(lista)+" MIN = "+ Collections.min(lista));
  214. }
  215. }
  216.  
  217.  
  218. import java.util.Scanner;
  219.  
  220.  
  221. public class Zadatak6
  222. {
  223.  
  224.  
  225. public static void main(String[] args)
  226. {
  227. double xmin, xmax, dx, x, y;
  228. Scanner scan = new Scanner(System.in);
  229.  
  230. System.out.print("xmin = ");
  231. xmin = scan.nextDouble();
  232.  
  233. System.out.print("xmax = ");
  234. xmax = scan.nextDouble();
  235.  
  236. System.out.print("dx = ");
  237. dx = scan.nextDouble();
  238.  
  239. System.out.println("=====================================");
  240. System.out.println("x \ty");
  241.  
  242. for(x = xmin; x <= xmax; x+=dx)
  243. {
  244. y = (x*x-2*x-2)/(x*x+1);
  245. System.out.println(x+"\t"+y);
  246. }
  247. }
  248.  
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement