-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDia.java
More file actions
135 lines (98 loc) · 3.99 KB
/
Copy pathTestDia.java
File metadata and controls
135 lines (98 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// library for the scannner
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
/**
* This class is used to print a two-dimensional integer array diagonally
* @author Pierre Paul Charbonnier <p.charbonnier@student.maastrichtuniversity.nl>
*/
public class TestDia {
public static void main(String[] args) {
/**
*I'm using a scannner called scan to fill the value of the column and the row.
*/
Scanner scan = new Scanner(System.in);
System.out.println(" " );
System.out.println("Enter the number of row of the first matrix : " );
int numberOfRowMatrix1 = scan.nextInt();
System.out.println(" " );
System.out.println("Enter the number of column of the first matrix : " );
int numberOfCulumnMatrix1 = scan.nextInt();
System.out.println(" " );
/**
*I am using random to fill the matrix with some " random number ".
*/
Random rand = new Random(9);
int[][] array = new int[numberOfCulumnMatrix1][numberOfRowMatrix1];
for( int i = 0 ; i < numberOfCulumnMatrix1 ; i++ ) {
for( int j = 0 ; j < numberOfRowMatrix1 ; j++) {
array[i][j] = rand.nextInt(numberOfRowMatrix1 * numberOfCulumnMatrix1 ) ;
}
}
/**
*I am using loops to nativigate in the matrix and then I'm printing the matrix then with System.out.print
*/
for( int i = 0 ; i < numberOfCulumnMatrix1 ; i++ ) {
for( int j = 0 ; j < numberOfRowMatrix1 ; j++ ) {
System.out.print("[ "+ array[i][j] + " "+ "]" );
}
System.out.println();
}
diagonalPrint(array);
System.out.println( );
System.out.println( );
System.out.println();
System.out.println(" Implement the length of yout new array.");
int lengthNew = scan.nextInt();
System.out.println("Give the range m for the numbers in the array (it goes from 0 to m-1)");
int m = scan.nextInt();
int[] vector = new int[lengthNew];
System.out.print("The randomly generated array is: ");
for(int i = 0; i<lengthNew; i++) {
vector [i] = ((int)(Math.random() * m ));
}
System.out.println(Arrays.toString(vector));
System.out.println("Give a teta under which the number for the recursions must be");
int teta = scan.nextInt();
int finish = allNumsWithin(vector,teta);
if(finish != 0) {
System.out.println("The shortest length is: "+ finish);
}
else System.out.println("There is no consecutive appearance for all of the numbers under "+m);
int [] risulta= extractSubVector(vector,3, 8);
System.out.println(Arrays.toString(risulta));
}
public static void diagonalPrint(int[][] M) {
int row = M.length ;
int colunm = M[0].length;
for(int i = 0; i< row; i++) {
for(int j = i, k = 0; j>= 0 && k<colunm; j--, k++) {
System.out.print(M[j][k]+"-");
}
}
for(int i = 0; i<colunm; i++) {
for(int j = row-1, k = 1 + i; j>= 0 && k<colunm; j--,k++) {
if(j == M.length-1 && k == M[0].length-1) {
System.out.print(M[j][k]);
break;
}
System.out.print(M[j][k]+"-");
}
}
}
public static boolean isTheGoodSecance(int[] goodvector, int L) {
return false ;
}
public static int allNumsWithin(int[] A, int k) {
// for (int i=0, int c=k-1;) {
return 0;
}
// }
public static int[] extractSubVector (int[] A, int begin, int end ) {
int returnVector[]= new int [end - begin] ;
for (int i = begin, j = 0 ; i < end ; i++, j++ ) {
returnVector[j]= A[i];
}
return returnVector;
}
}