Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- int[] arr = { 4, 2, 7, 1, 8, 4, 23, 34, 674 };
- int min, max;
- min = max = arr[0];
- for (int x : arr) {
- min = Math.min(min, x);
- max = Math.max(max, x);
- }
- // app 2
- int[] fibarr = fib(10);
- print(fibarr);
- // app 5
- int n = 3;
- int[][] matr1 = {
- { 1, 2, 3 },
- { 4, 5, 6 },
- { 7, 8, 9 }
- };
- int[][] matr2 = {
- { 0, 2, 8 },
- { 4, 3, 4 },
- { 3, 1, 7 }
- };
- int[][] result = new int[n][];
- for (int i = 0; i < n; i++) {
- result[i] = new int[n];
- for (int j = 0; j < n; j++) {
- result[i][j] = 0;
- for (int x = 0; x < n; x++)
- result[i][j] += matr1[i][x] * matr2[x][j];
- }
- print(result[i]);
- }
- }
- public static void print(int[] ar) {
- for (int x : ar)
- System.out.printf("%d ", x);
- System.out.println();
- }
- public static int[] fib(int n) {
- if (n == 1)
- return new int[] { 0 };
- if (n == 2)
- return new int[] { 0, 1 };
- int[] arr = new int[n];
- arr[0] = 0;
- arr[1] = 1;
- for (int i = 2; i < n; i++) {
- arr[i] = arr[i-1] + arr[i-2];
- }
- return arr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement