-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo.java
67 lines (65 loc) · 1.61 KB
/
Demo.java
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
public class Demo{
public static void printLoop(int n){
for(int i = 1; i <= n;i++){
for(int j = i -1; j < n; j++){
System.out.print(i);
}
System.out.println();
}
}
public static String arrToString(int[] arr){
String newStr = "{";
String actualStr = "";
for (int i = 0;i<arr.length;i++){
if(arr.length -1 > 0){
newStr += arr[i] + ", ";
}
else{
newStr += arr[i];
}
}
if(arr.length - 1 <= 0){
return newStr + "}";
}
for (int j = 0; j < newStr.length()-2;j++){
actualStr += newStr.substring(j,j+1);
}
return actualStr + "}";
}
public static String arrayDeepToString(int[][]arr){
String newStr1 = "{";
String actualStr1 = "";
for (int i = 0;i < arr.length;i++){
newStr1 += arrToString(arr[i]) + ", ";
}
for (int j = 0; j < newStr1.length()-2;j++){
actualStr1 += newStr1.substring(j,j+1);
}
return actualStr1 + "}";
}
public static int[][] create2DArray(int rows, int cols, int maxValue){
int[][]Arr = new int[rows][cols];
for (int i = 0; i < rows;i++){
for (int j = 0; j < cols;j++){
Arr[i][j] = (int)Math.round(Math.random() * maxValue);
}
}
return Arr;
}
public static int[][] create2DArrayRandomized(int rows, int cols, int maxValue){
int[][]arr = new int[rows][];
for (int i = 0; i < rows; i++){
arr[i] = new int[(int)(Math.random() * (cols))];
for (int j = 0; j < arr[i].length; j++){
arr[i][j] = (int)Math.round(Math.random() * maxValue);
}
}
return arr;
}
public static void main(String[] args){
if (args.length == 0){
printLoop(5);
}
else {printLoop(Integer.parseInt(args[0]));}
}
}