-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlgotithms
114 lines (87 loc) · 3.07 KB
/
Algotithms
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
//¿Que interfaz es implementada por java.util.Hashtable?
public class Hashtable<K,V>
extends Dictionary<K,V>
implements Map<K,V>, Cloneable, Serializable
// Que método se utiliza para iniciar la ejecución de un thread?
metodo start.
Arrays.sort(myArray);
System.out.println(myArray[myArray.length-1]);
for ( int i=0; i < n ;i++){
for (int j=0; j<n;j++){
dibujo[x][i] = "_";
}
dibujo[i][n - i - 1] = "X";
dibujo[i][i] = "X";
}
for ( int i=0; i < n ;i++){
for (int j=0; j<n;j++){
System.out.print(dibujo[x][i]);
}
System.out.println();
}
int cola=n;
int punta=0;
for ( int i=0; i < n ;i++){
for (int j=0; j<n;j++){
if(j==cola || j===punta)
{System.out.print('X');}
else
{System.out.print('_');}
}
cola--;
punta++;
}
import java.util.*;
public class MyClass {
static int[] myArray = {1,2,2,4,5,6,7,8,8,8};
public static void main(String args[]) {
Map<Integer, Integer> occurrences = new HashMap<Integer, Integer>();
for ( Integer word : myArray ) {
Integer oldCount = occurrences.get(word);
if ( oldCount == null ) {
oldCount = 0;
}
occurrences.put(word, oldCount + 1);
}
//System.out.println(occurrences);
Integer Maxkey=occurrences.entrySet().stream().max((entry1, entry2) -> entry1.getValue() > entry2.getValue() ? 1 : -1).get().getKey();
System.out.println("Longest: "+occurrences.get(Maxkey));
System.out.println("Number: "+Maxkey);
}
}
import java.util.*;
public class MyClass {
static String[] myArray = {"a", "b", "c", "d", "d", "c", "b", "a"};
public static void main(String args[]) {
String[] mirror=Arrays.copyOfRange(myArray,0,myArray.length/2);
String[] mirror2=Arrays.copyOfRange(myArray,myArray.length/2,myArray.length);
Collections.reverse(Arrays.asList(mirror2));
System.out.println(Arrays.toString(mirror));
System.out.println(Arrays.toString(mirror2));
System.out.println(Arrays.toString(mirror).equals(Arrays.toString(mirror2)));
String res=Arrays.toString(mirror).equals(Arrays.toString(mirror2))?"Symmetric":"Asymmetric";
System.out.println(res);
}
}
//histograma
public static void main (String args[]) {
int size=Arrays.stream(myArray).max().getAsInt();
Map<Integer, String> occurrences = new HashMap<Integer, String>();
for ( Integer word : myArray )
{
String oldCount = null;
oldCount = occurrences.get(word);
if ( oldCount == null ) {
occurrences.put(word, "*");
continue;
}
occurrences.put(word, oldCount + "*");
}
//fill not present
for (int x=1;x<= size;x++ )
{
String pos = occurrences.get(x);
if ( pos == null ) { System.out.println(x+": "); continue; }
System.out.println(x+": "+pos);
}
}