-
Notifications
You must be signed in to change notification settings - Fork 1
/
Arrays_Gonz.java
161 lines (136 loc) · 3.28 KB
/
Arrays_Gonz.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*Brandon Gonzalez
Please forgive the stupid innefeciency that is prog7.11 :(
R7.7 b, c, d
R7.8 R7.11 a, c
R7.12 c
R7.14
R7.17
Prog7.9
Prog7.11
7.7b.
int[] cow = new int[12];
for(int i=0; i < 20; i+=2){
cow[i] = i/2;
}
c.
int[] cow = new cow[10]
for(int i = 0; i < 10; i++)
int[i] = (i +1)(i+1);
d.
int[] cow = new cow[10];
for(i=0; i < 10; i++)
int[i] = 0;
7.8
import java.util.random
int[] a = new int[10];
Random gen = new Random();
for(int i = 0; i < 10; ++i)
a[i] = gen.nextInt(100);
7.11 a.
double sum;
for(int i = 0; i < values.length; ++i)
sum += values[i];
c. for(int i = 0; i < values.length; ++i)
values[i] = 2 * values[i];
7.12 c
int i = 0;
for(double element : values){
if(element == target)
return i;
i++;
}
7.14 pos is never actually declared;
7.17. Parallel arrays are a set of arrays that represent different data fields, but pertain to the same overall data set
An example would be having 2 arrays, one for first name and the other for last name. The 0 element of both belong to the
same overall set. The problem with them is that it takes alot of effort to delete or add an overall data set to them.
They are really innefecient. Bad locality of reference is probably the biggest. They can be avoided by making multi dimensional arrays(lol)
or creating an object that contains the various sets of data inside of it, then make an array of that object.
*/
import java.util.Random;
public class Arrays_Gonz{
public static void main(String[] args)
{
P79();
System.out.println();
P711();
}
public static void P79()
{
Random gen = new Random();
boolean inRun = false;
int prev = -9999;
int[] roll = new int[22];
roll[21] = 0;
for(int i = 0; i < roll.length - 1; ++i)
roll[i] = gen.nextInt(6) + 1;
for(int i = 0; i < roll.length - 1; ++i)
{
if(inRun)
{
if(roll[i]!= roll[i-1]) {
System.out.printf(")");
inRun = false;
}
}
else if(!inRun)
{
if(roll[i] == roll[i+1])
{
System.out.printf("(");
inRun = true;
}
}
System.out.printf("%d", roll[i]);
}
if(inRun)
System.out.printf(")");
System.out.println();
}
//sorta had a brain fart last night and all logic failed me.
public static void P711()
{
boolean[] stalls = new boolean[10];
int prevpos, curPos, futurePos;
int places[][] = new int[10][3];
int x, y;
boolean spotFound = false;
while(!(stalls[0] && stalls[1] && stalls[2] && stalls[3] && stalls[4] && stalls[5] && stalls[6] && stalls[7] && stalls[8] && stalls[9]))
{
prevpos = 0;
curPos = 0;
x = 0;
y = 0;
for(int i = 0; i < ) //Fills in the differences
{
if(stalls[curPos])
{
places[x][0] = prevpos;
places[x][1] = curPos;
places[x][2] = curPos - prevpos;
x++;
prevpos = curPos;
}
curPos++;
}
int max = -99999;
int twodindex = 0;
for(int i = 0; i < places.length; i++)
{
if(places[i][2] > max) {
max = places[i][2];
twodindex = i;
}
}
int temp = (int) places[twodindex][0] + places[twodindex][2]/2;
stalls[temp] = true;
for(int i = 0; i < stalls.length; ++i)
{
if (stalls[i])
System.out.printf("x");
else
System.out.printf("_");
}
System.out.println();
}
}
}