Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. int[] arr = { 4, 2, 7, 1, 8, 4, 23, 34, 674 };
  6.  
  7. int min, max;
  8. min = max = arr[0];
  9. for (int x : arr) {
  10. min = Math.min(min, x);
  11. max = Math.max(max, x);
  12. }
  13.  
  14. // app 2
  15. int[] fibarr = fib(10);
  16. print(fibarr);
  17.  
  18. // app 5
  19. int n = 3;
  20. int[][] matr1 = {
  21. { 1, 2, 3 },
  22. { 4, 5, 6 },
  23. { 7, 8, 9 }
  24. };
  25. int[][] matr2 = {
  26. { 0, 2, 8 },
  27. { 4, 3, 4 },
  28. { 3, 1, 7 }
  29. };
  30.  
  31. int[][] result = new int[n][];
  32. for (int i = 0; i < n; i++) {
  33. result[i] = new int[n];
  34. for (int j = 0; j < n; j++) {
  35. result[i][j] = 0;
  36.  
  37. for (int x = 0; x < n; x++)
  38. result[i][j] += matr1[i][x] * matr2[x][j];
  39. }
  40. print(result[i]);
  41. }
  42. }
  43.  
  44. public static void print(int[] ar) {
  45. for (int x : ar)
  46. System.out.printf("%d ", x);
  47. System.out.println();
  48. }
  49.  
  50. public static int[] fib(int n) {
  51. if (n == 1)
  52. return new int[] { 0 };
  53. if (n == 2)
  54. return new int[] { 0, 1 };
  55.  
  56. int[] arr = new int[n];
  57. arr[0] = 0;
  58. arr[1] = 1;
  59. for (int i = 2; i < n; i++) {
  60. arr[i] = arr[i-1] + arr[i-2];
  61. }
  62. return arr;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement