Results 1 to 15 of 15

Thread: Java Array Help

  1. #1
    md69holla is offline Member
    Join Date
    Feb 2010
    Posts
    13
    Rep Power
    0

    Default Java Array Help

    Hi guys! Ok so this is my first year in college and I am having a lot of trouble with my computer course which mostly consist of writing java programs. I am falling way behind in class and i have a mid term due next week. It is REALLY causing a lot of stress on me. I would usually go for extra help but I am super busy with mid term papers and studying. THANK YOU!

    Please create 1 file called ArrayLab. In that file you will write methods that represent each one of the objectives below. When the methods are complete you will create the main method, create a new ArrayLab object and invoke each of the methods you created.

    a.) In a method declare an array that stores the values from 1 to 10. Initialize and print the values using a single for loop.
    b.) In a method declare an array that stores the names of your family. You should declare and initialize the values using the short hand method. Use a for loop to print out the values
    c.) In a method declare an array that stores 4 lucky numbers. You should add the values long hand. You will need to use a for loop to print the values
    d.) In a method declare a multidimensional array that will store the times tables up through 10. You will need to use 2 for loops to store the values and print them out

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default

    And now what? I do hope that you're not expecting us to do your work. Give it a go and if you're stuck ask specific questions here.

    kind regards,

    Jos

  3. #3
    md69holla is offline Member
    Join Date
    Feb 2010
    Posts
    13
    Rep Power
    0

    Default

    i dont know how. its my first java class. and i fell too far behind trying to learn the other stuff.

  4. #4
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    ever tried looking for the sun tutorials, thats how we all learn it
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  5. #5
    adityasirohi is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    Lets help this guy out, but md69holla, i would not give u 100% code. I will give an outline and u have to fill in the blanks. Is that okay with you. You have to put some effort.

  6. #6
    senorbum is offline Member
    Join Date
    Aug 2009
    Posts
    76
    Rep Power
    0

    Default

    Quote Originally Posted by adityasirohi View Post
    Lets help this guy out, but md69holla, i would not give u 100% code. I will give an outline and u have to fill in the blanks. Is that okay with you. You have to put some effort.
    A) Why help out somebody who isn't willing to put in the time to actually learn something?
    B) Why be responsible for helping somebody cheat?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I agree with senor bum. So far the original poster has shown no inclination to put in any effort on their own. Until he does that, it appears that he'll be getting the grade he deserves.

  8. #8
    md69holla is offline Member
    Join Date
    Feb 2010
    Posts
    13
    Rep Power
    0

    Default

    thats what i got so far. i cannot figure the rest out.

    a. int[] numArray = new int[10];
    for(i = 0; 1 < numArray.lengh;i++)
    {

    numArray[i] = i + 1;

    System.out.println("" + numArray[i]);
    }

    b. String[] names = {"Rich", "Andrew", "Marissa"};


    c. int[] luckyNums = new int[4];
    luckyNums[0] = 3;
    luckyNums[1] = 7;


    d.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    You've just thrown some code at the page. The questions in your original post talked about "In a method".

    That aside, considering you managed to write a loop in the first question, why you haven't managed it in the others I don't know.

  10. #10
    md69holla is offline Member
    Join Date
    Feb 2010
    Posts
    13
    Rep Power
    0

    Default

    a. int[] numArray = new int[10];
    for(i = 0; 1 < numArray.lengh;i++)
    {

    numArray[i] = i + 1;

    System.out.println( numArray[i]);
    }

    b. String[] names = {"Rich", "Andrew", "Marissa"};

    c. int[] luckyNums = new int[4];
    luckyNums[0] = 3;
    luckyNums[1] = 7;
    luckyNums[2] = 12;
    luckyNums[3] = 21;

    for(i = 0; 1 < luckyNums.lengh;i++)
    {

    luckyNums[i] = i + 1;

    System.out.println( luckyNums[i]);

    } // is that right? im not sure what "1" needs to be an "i".


    d. int[][] multiArray = new int[10][10];
    for(i = 0; 1 < multiArray.lengh;i++)
    {

    multiArray[i] = i + 1;

    System.out.println( multiArray[i]);
    } //thats what i have for D so far?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Have you tried to run them and see if work as you expect?

  12. #12
    md69holla is offline Member
    Join Date
    Feb 2010
    Posts
    13
    Rep Power
    0

    Default

    no because i know they dont. im not very good at java i need to take this class but it doesnt have to do with my major.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    How do you know they don't if you don't actually run them?

    How do expect to correct them if you don't know what they do, or where they're going wrong? Even compiling them will at least give you some pointers...

  14. #14
    md69holla is offline Member
    Join Date
    Feb 2010
    Posts
    13
    Rep Power
    0

    Default

    i just need help with d. i dont get how to put a loop into a loop.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    The same way you did the first loop, only using a different name for the variable (ie not "i" as you've used in the outer loop)...the usual thing is "j". Then you can assign to your array as:
    multiArray[i][j] = ...whatever it is you're supposed to be assigning.

    So:
    Java Code:
    for (...) {
        for (...) {
            // Assign here.
        }
    }

Similar Threads

  1. How to transfer 1D array in JAVA to 3D array in C
    By fishwater00 in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 06:24 PM
  2. how to pass array in java?
    By sivasayanth in forum New To Java
    Replies: 3
    Last Post: 01-13-2008, 04:33 PM
  3. how to convert a Java array to a java stack?
    By pompeez in forum New To Java
    Replies: 2
    Last Post: 08-13-2007, 02:41 PM
  4. Help with array in java
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:03 AM
  5. Help with array and files in java
    By fernando in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:52 PM

Posting Permissions

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