Results 1 to 15 of 15
Thread: Java Array Help
- 02-12-2010, 03:59 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 13
- Rep Power
- 0
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
- 02-12-2010, 04:12 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
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
- 02-12-2010, 04:34 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 13
- Rep Power
- 0
i dont know how. its my first java class. and i fell too far behind trying to learn the other stuff.
- 02-12-2010, 04:47 PM #4
Senior Member
- Join Date
- Dec 2009
- Posts
- 104
- Rep Power
- 0
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
- 02-12-2010, 09:31 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
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.
- 02-12-2010, 10:11 PM #6
Member
- Join Date
- Aug 2009
- Posts
- 76
- Rep Power
- 0
-
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.
- 02-15-2010, 03:58 PM #8
Member
- Join Date
- Feb 2010
- Posts
- 13
- Rep Power
- 0
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.
- 02-15-2010, 04:43 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 02-15-2010, 05:20 PM #10
Member
- Join Date
- Feb 2010
- Posts
- 13
- Rep Power
- 0
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?
- 02-15-2010, 05:23 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Have you tried to run them and see if work as you expect?
- 02-15-2010, 05:33 PM #12
Member
- Join Date
- Feb 2010
- Posts
- 13
- Rep Power
- 0
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.
- 02-15-2010, 05:38 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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...
- 02-15-2010, 05:49 PM #14
Member
- Join Date
- Feb 2010
- Posts
- 13
- Rep Power
- 0
i just need help with d. i dont get how to put a loop into a loop.
- 02-15-2010, 06:02 PM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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
-
How to transfer 1D array in JAVA to 3D array in C
By fishwater00 in forum New To JavaReplies: 0Last Post: 07-31-2009, 06:24 PM -
how to pass array in java?
By sivasayanth in forum New To JavaReplies: 3Last Post: 01-13-2008, 04:33 PM -
how to convert a Java array to a java stack?
By pompeez in forum New To JavaReplies: 2Last Post: 08-13-2007, 02:41 PM -
Help with array in java
By coco in forum New To JavaReplies: 1Last Post: 08-06-2007, 04:03 AM -
Help with array and files in java
By fernando in forum New To JavaReplies: 1Last Post: 07-31-2007, 07:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks