Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By jlczuk

Thread: Complete newbie

  1. #1
    diegoigaete is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default 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. #2
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default 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
    Fubarable likes this.

  3. #3
    diegoigaete is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default 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. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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. #5
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default 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. #6
    diegoigaete is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default 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. #7
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default 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.

Similar Threads

  1. Steps to create web app for complete newbie
    By motorola in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 10-16-2011, 11:56 AM
  2. Jar file not complete
    By desoky725 in forum NetBeans
    Replies: 6
    Last Post: 09-23-2011, 07:33 AM
  3. complete sequence
    By aizen92 in forum New To Java
    Replies: 25
    Last Post: 12-29-2010, 11:58 AM
  4. can anyone help me,a complete newbie?
    By keye906 in forum New To Java
    Replies: 13
    Last Post: 06-02-2010, 01:56 PM
  5. Download the Complete API?
    By JDCAce in forum NetBeans
    Replies: 2
    Last Post: 10-02-2008, 01:02 AM

Posting Permissions

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