# Thread: Complete newbie

1. Member
Join Date
Apr 2012
Posts
3
Rep Power
0

## Complete newbie

I just starting getting into java and am taking a class at school. They are teaching us introduction to java so I gotta keep the code simple.

I need to create a method to inialize two int arrays, vector1 and vector2, with 10 elements with the random.math method.

public class Calculo
{

int [] vector1;
int [] vector2;

public void inicializar(int [] vector)
{
int [] vector1 = new int [10](Math.random());
int[] vector2 = new int[10][(Math.random()];

}

}

I know this is wrong, but this is what I was shooting for or thought was the right path..

2. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Complete newbie

First, why do you think you need the vector parameter as an input? You aren't using it anywhere and you description of the assignment does not mention that you are given any input to work with.

Next, think LOOPS! The whole point of this exercise seems to be to get you to think about how you can use a loop, like a for or while loop, to initialize the vectors.

You should read The for Statement and The while and do-while Statements

3. Member
Join Date
Apr 2012
Posts
3
Rep Power
0

## Re: Complete newbie

The assignment is to create a class named "Calculo" (Im from South America) with the following characteristics:
1. Declare two array attributes, vector1 and vector2, type int.
2. Write a method, named "inicializar", which will initiate vector1 and vector2 with 10 random elements.
3. Write a method, named "mostrarvector", which will show/print both vector1 and vector2.

There are many more points to the assignment, that Id like to try out, but I seem to be stuck with this creating the random 10 element array.

4. ## Re: Complete newbie

Then read the tutorials that are linked to in the helpful post above and try to use for loops as has been suggested. If you get stuck, show your latest code.

5. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Complete newbie

I understood enough depsite the language difference. That doesn't change what I posted.

You created the class and you've declared the two vectors. My reply was trying to get you to think about how you do item 2. You are going to have to do the reading to learn how to use a loop to initialize your vectors. You don't HAVE to use a loop, but given the assignment, that is clearly what your teacher wants.

6. Member
Join Date
Apr 2012
Posts
3
Rep Power
0

## Re: Complete newbie

I understand the loop, and how to use the for. Last semester I had C programming. My question goes strictly out to the create the 10 int element array using the Math.random command. I know what I put as my code is wrong for initializing it. For example, should I change the public void part?
I made some changes, its still giving me an error in Netbeans, but maybe Im in the right path?

public class Calculo
{

int [] vector1;
int [] vector2;

public void inicializar() //should i keep it like this, or like i had it before?
{
int [] = new int [10](Math.random()); //not sure how to do this
int [] vector2 = new int[10]Math.random();
}

public void mostrarVector ()
{

for(i=0;i<10;i++)
{
System.out.println("El contenido del vector1 es: " +i);
}
}
}

Thanks for actually giving me an useful answer jlczuk

7. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Complete newbie

The "public void" has nothing to do with this. All that says is the method is publicly visible to your main() and void simply says the method does not return anything.

Your problem is you don't understand how Math.random() works, as demonstrated by how you've used it. Do a google search on "Java Math.random" and read what it does. Then think about how you could use it in a loop to initialize your vectors.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•