-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathMain.java
More file actions
178 lines (148 loc) · 4.82 KB
/
Main.java
File metadata and controls
178 lines (148 loc) · 4.82 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Example for Arrays
*/
import java.util.Scanner;
class Main
{
/*
* This one will have public static void main
*/
public static void main( String[] args)
{
/*
* SET UP
* We are going to ask the user to input an integer
* and we will call it
n
*/
Scanner s = new Scanner(System.in);
System.out.print(" Please type in an integer :");
int n = s.nextInt();
/*
* Task 1. Create an array of integers from 0 to n-1
* call this array ar1. Print it out below.
*/
System.out.println("*** PRINTING ar1 *");
/*
* Task 2. Create a new array called ar2.
* Copy the elements of ar1 into ar2.
*/
/*
* Task 3. Add 1 to each element in ar1. Print it out below
*/
/*
* task 4. Create a new array called ar3.
* Copy the elements of ar1 into ar3. Then do it again
* For example
* ar1: 1 2 3
* ar3: 1 2 3 0 1 2 3
*/
/*
* Task 5. Switch the first and last element of ar1.
* print out the new ar1. Then switch them back
*/
/*
* Task 6A. Print the 2nd to (n-1)th elements of ar1
* Task 6B: Print out just the odd numbers in ar1
* Task 6C: Print out the elements of ar1 when
* the indices are multiples of 3
*
*/
/*
* Task 7. For each element in ar1,
* If the element is even: leave alone
* if the element is odd, multiply by 10
* print out the new ar1
* Example
* ar[0]=10
* ar[1]=2
* ar[2]=30
* ar[3]=4
*/
/*
* Task 8
* Create an array called ar2odds
* If the index of ar2 is odd, copy it to ar2odds.
* If not, do not
* ar2[0]=0
* ar2[1]=1 -> ar2odds[0]=1
* ar2[2]=2
* ar2[3]=3 -> ar2odds[1]=3
*/
/*
* Task 9. In the array ar2, count how many odd numbers you
* have. Then create an ew array called ar4. Copy just the odd
* numbers from ar1 into ar4. Print ar4
*/
/*
* Task 10. Shift the elements of ar4 right by 1
* For example
* old ar4: 1 3 5 7 9
* new ar4 9 1 3 5 7
*/
/*
* Task 11. Reverse the order of elements in ar2
*/
/*
* Task 12:
* Create an array of Strings called ar5.
*
* Each element is a word of the following phrase
*
*
* Four score and seven years ago our fathers brought forth on
* this continent a new nation
*
*. ar5[0] = "Four"
* ar5[1] = "score"
*
* Create another array of ints called ar6. Write a for loop that
* will iterate through each element in ar5 and the length of the
* word is the element in ar6.
*
* ar5[0]= "Four" ar6[0]=4
* ar5[1]="score" ar6[1]=5
* ar5[2]="and" ar6[2]=3
*
* Count how many words have more than 5 letters.
*/
/*
* Task 13
* Create an array called monsterArray of 5 Monsters.
* The name of the monsters are
* "Cookie"
* "Grover"
* "Oscar the Grouch"
* "Elmo"
* "Rosita"
*
* Print out their names
* Use a for loop to print out the names of monster that start with
* a vowel
*/
/*
* Task 14
* Create an array of integers from 3 to 94 and call it arx
* Create an array of the indices of arx when the item is
* divisible by 3. Call this arindex
* arx[0]=94
* arx[1]=95
* arx[2]=96 // this is divisible. Index is 2
* arx[3]=97
* arx[4]=98
* arx[5]=99 // this is divisible Index is 5
*
* So arindex[0]=2
* arindex[1]=5
*/
/*
* Create an arrary called "fb" and calculate the
* first 10 fibonacci sequence. You start with
* fb[0]=1
* fb[1]=1
* fb[2]=fb[0]+fb[1]
* fb[3]=fb[1]+fb[2]
* fb[4]=fb[2]+fb[3]
*/
}
}