Repository navigation
Expand file tree
/
Copy pathDemo.java
More file actions
61 lines (61 loc) · 1.84 KB
/
Copy pathDemo.java
File metadata and controls
61 lines (61 loc) · 1.84 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
class Demo{
//static int[][] testBoi = new int[][] {{6,9,4},{2,0,1}};
public static void main(String[] args) {
if (args.length == 0){
printLoop(5);
}else{
printLoop(Integer.parseInt(args[0]));
}
//System.out.println(arrrayDeepToString(testBoi));
//System.out.println(arrrayDeepToString(create2DArray(4,4,4)).replace("}, ","},\n "));
//System.out.println(arrrayDeepToString(create2DArrayRandomized(4,4,4)).replace("}, ","},\n "));
}
public static void printLoop(int n){
for(int i = 1; i<=n; i++){
for(int v = n; v>=i; v--){
System.out.print(i);
}
System.out.println();
}
}
public static String arrToString(int[] arr){
String result = "{";
for (int i = 0; i<arr.length; i++){
result += arr[i];
if (i<arr.length-1){
result += ", ";
}
}
return result+"}";
}
public static String arrayDeepToString(int[][] arr){
String result = "{";
for(int i = 0; i<arr.length;i++){
result += arrToString(arr[i]);
if (i<arr.length-1){
result += ", ";
}
}
return result+"}";
}
public static int[][] create2DArray(int rows, int cols, int maxValue){
int[][] result = new int[rows][cols];
for (int i = 0; i<rows; i++){
for (int v = 0; v<cols; v++){
result[i][v] = (int)(Math.random()*(double)(maxValue+1));
}
}
return result;
}
public static int[][] create2DArrayRandomized(int rows, int cols, int maxValue){
int[][] result = new int[rows][];
for (int i = 0; i<rows; i++){
int randomLength = (int)(Math.random()*(double)(cols+1));
result[i] = new int[randomLength];
for (int v = 0; v<randomLength; v++){
result[i][v] = (int)(Math.random()*(double)(maxValue+1));
}
}
return result;
}
}