Arrays Assignment help, plz read
Author |
Message |
sh4dow
|
Posted: Tue Dec 16, 2008 6:31 pm Post subject: Arrays Assignment help, plz read |
|
|
1. Fill up array list1 with 20 random integers between 1 and 100.
2. Multiply each element in list1 by its index number and place the value in array list2.
3. Replace the value of the elements in all odd number indexes in list2 with 0.
4. Add list1 and list2 placing the value in list1.
5. Multipy each element average of the elements in list1 then list 2.
6. Invert the array list2 placing the values in list1.
7. Input a numeric value to search for in list1, and output the results, with location if found.
So this was the question I was given.
Java: | public class ArrayQ {
public static void main (String[] args ) {
int[] list1 = new int[20];
generate (list1 );
printArray (list1 );
System. out. println();
int[] list2 = new int[20];
multiplyArray (list1,list2 );
printArray (list2 );
}
public static void oddArray (int x []){
for (int i= 0;i<x. length;i=i+ 2){
}
}
public static void multiplyArray (int x [], int y []){
for (int i= 0;i<x. length;i++ ){
y [i ]= x [i ]*i;
}
}
public static void printArray ( int x []){
for (int i= 0;i<x. length;i++ ){
System. out. print(x [i ]+ " ");
}
}
public static void generate (int x []){
for (int i= 0;i<x. length;i++ ){
x [i ]= (int)(Math. random()* 100+ 1);
}
}
} |
This is what I have so far . I don't know how to do the rest. I have answered them up to three and I need major help now.
Moderation: for the love of everything unholy people, SYNTAX or CODE tags! - wtd |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
wtd
|
Posted: Tue Dec 16, 2008 6:55 pm Post subject: RE:Arrays Assignment help, plz read |
|
|
And now, as good-looking as Java code can get:
Java: | public class ArrayQ {
public static void main (String[] args ) {
int[] list1 = new int[20];
generate (list1 );
printArray (list1 );
System. out. println();
int[] list2 = new int[20];
multiplyArray (list1, list2 );
printArray (list2 );
}
public static void oddArray (int[] x ) {
for (int i = 0; i < x. length; i = i + 2) {
}
}
public static void multiplyArray (int[] x, int[] y ) {
for (int i = 0; i < x. length; i++ ) {
y [i ] = x [i ] * i;
}
}
public static void printArray (int[] x ) {
for (int i = 0; i < x. length; i++ ) {
System. out. print(x [i ] + " ");
}
}
public static void generate (int[] x ) {
for (int i = 0; i < x. length; i++ ) {
x [i ] = (int)(Math. random() * 100 + 1);
}
}
} |
|
|
|
|
|
 |
wtd
|
Posted: Tue Dec 16, 2008 6:57 pm Post subject: RE:Arrays Assignment help, plz read |
|
|
So you have figured out how to iterate from 0 to 19. Both arrays are of the same length. You also know how to modify an array. Number 4 should be easy. |
|
|
|
|
 |
|
|