Think of this line of code as a type writer. I won't get to why it's like a type writer yet but bear with me: This is the confusing part: for (int row = 0; row
Maybe people are failing to understand this easily because Bucky hasn't told us something which might seem obvious but people might not realize. If u have a 2D Array, int arry[][] = { {1,2,3}, {4,5,6} }; arry.length = 2. Why? Because in the main array "Arry" There are 2 smaller arrays. That's why it will give you the number of arrays inside your array. If you want to know the length of one of the smaller arrays inside Arry then you would have to do: arry[0].length to know the length of the first smaller array (row). Why? Because 0 means the first as speaking in computer language. arry[1].length would give u the length of the second smaller array or second row.
i'll use a single array for this..note(this is just my own way of doing it, there may be multiple easier ways) int arr[] = {1,2,3,4,5}; for(int x = 0; x < arr.length; x ++) { // check if they have no remainder(i.e 0) when divided by 2 if(arr[x]%2 == 0) { System.out.println(arr[x]); } } hope this helps :)
for those of you who have just lost your mind... type this out, then think logically what the for loop column is doing, when it ends and what then happens to the for row loop... the overall "x" part of it is applied to firstarray and second array when calling the "display" method (or whatever you called it)... I really do hope this helps.
I'm up to the 51st Java tutorial now but if you had a memory like mine you will realise you can't just simply watch these videos and move on. I did just that the first time, got to the 50th tutorial and forgot everything in the earlier ones and had to constantly re-watch. This time around I'm taking notes, taking my time and making my own examples. I've learned MUCH more because of this new approach and have a higher understanding of how things work in Java.
@@scooby-dooafterlife6969 oh, wow. Probably. I don't remember. LOL. I now program using C# and Unity. Although I enjoy working with Unreal and Godot is also great for beginners.
Remember cartesian plane math? this is exactly it. int a[][] is sam as a[x][y], x is horizontal and x is vertical. also bar graphs and line graphs, X and Y axis, Y is dependent on X. in this multidimensional array the column which is Y is dependent on X which is the row.
I have to admit this is a much better way of going about it. I am simply writing out the code and trying to gain a rudimentary understanding but, once I get to about 40/50, I'm going to start again and take notes etc.
To be honest, I think doing what you did is the best method. The purpose of going over everything once is basically to help give you a bigger picture view of how Java works.. I will probably get to about 50 before going back and restarting. I won't remember much, but I'll have a much better understanding due to having gone over everything once before. It's hard to watch something for the first time and take notes. Much easier the second time around!
oh man i love you - thank you dude - I am in my second level Java class and I had problems with arays and multidimensional arrays - truly, you broke it down soooooooo easily. I wil follow you forever my man. Thanks again. GW Kennesaw State U.
Both. I build the program(s) in eclipse while watching the videos and pause to take notes. I have a really horrid memory so taking notes while building the program helps me remember and better understand what I am doing. It also helps when I wish to look over them in the future instead of having to rely on skipping through the videos and finding it.
Wuhuu, had a lil struggle understanding this at first, but after going through it one step at a time, it all makes perfect sense :D I bet you all know what kind of sensational feeling I'm talking about ^^ Thanks so much for these tuts Bucky :)
Bucky is at the top of my list for tutorials. A text version of this is H&L uk google it its awsome equivalent to Bucky. Books 1st Beginer Java for dummies then head first java and then java patterns. Start with Bucky. Important to use all resources even if your going over the same material especially if your going over the same material Bucky dosent explain everything. But does the best vid tutorials in my opinion.
i took java introduction to programming it went great and finished but i wanted to expend my knowledge and got here i really enjoy your videos thanks for the help!
@HammockerSam Better explenation (soz for bad explanation in earlier posts): Your in the first for loop: row = 0; Your in for loop in the for loop: row still 0 because it hasn't incremented yet; at that moment x[row].length equals x[0].length, which means, the length of the numbers that are in the first array. Now it has that number (for example 10) it knows that it should make that many colums. after that it's gonna restart the loop, and this will go on until row
since x is a multidimensional array, x.length refers to how many arrays are in x. In the case of {{1,2,3},{4,5,6}} x.length would be 2 (0 and 1) because there are two arrays. x[row].length refers to how many numbers are in an array in a multidimensional array. Hope this helps!
These videos are all delicious! They keep getting better. I think you've made a programmer out of me, Bucky. I also love how you just throw the code out there while you are teaching. It is so easy to understand that way. P.s keep making reusable code like this that passes things to methods to be processed. Me gusta.
-> Loopception, Taking notes is something nobody likes to do, but you are right it is necessary. I knew that I should have been taking notes by Lec. 3. Here I am on 34. I have written four small Java programs by now and I still have to refer back to things as simple as the for loop video, to get any thing done. I think that i am going to backtrack tomorrow and jot down the highlights. That way I do not get any further behind. BTW, I am in a Java class in college. Bucky is better.
The int x[][], as far as I understood, is simply to tell what kind of method you're going to use. You can later use that method to place any multi dimensional array in there, so it will place your array values in the x[][]= method. When you look at for example "display(firstarray);".. it just takes the values of the firstarray and places it in the display method, so x[][] will equal exactly what your firstarray equals. It will do the method calculations and display it in a modified style.
What Krazy92 said. The reason it saves us time is that it means we don't have to write out a new piece of code every time we want to print an array. If you have 100 arrays and you want to print them all out, it's easier to type: display(array1); display(array2); etc. ...rather than typing out two for loops and a few print statements every time.
@HammockerSam Example: Your in the loop for the first time, so row=0. that means that it's gonna look at x[0] (in this case so it's gonna look at the length of the first array in the multidimensional array (array in array) that you send to the method as x value) Then the method .length will calculate the length of the array, so x[0] will look how many numbers are in the first array of the array, and this is necessary since it needs to know how many numbers to print.
The x.length means you're getting the length of the x so in this case for the first array the length of x is 2 because we have two rows. For the second array the length of x is 3 because we have three rows. The x[row].length means you're getting the length of x[row] so for the first loop, it gets the length of x[0], for the second loop, it gets the length of x[1] and so on if there's more than one column in that row. In short x[row].length is used to know the length of column in that row.
Irrespective of what IDE you use the array elements must be dislplayed in different lines. Because we added an empty line statement : System.out.println(); after the column for loop. you might have forgotten to add this line if you arent getting the rows in separate lines.
A couple good practice tips: Change your arrays and method to display strings instead of integers, and call the display method from a different class (I used the tuna class we created way back when).
say if string x = "x" and string y = "y", to compare the two for EXACTness, you would use: if(x.equals(y)){} the above would be case sensitive, and if you don't want it to be case sensitive, you can use this: if(x.equalsIgnoreCase(y){} hope this helps!
bucky thanks that's sooo helpfull ..just one note ..for method Display Line 16..exact..[System.out.print(x[row][column]+"\t");] U didn't mention that "println" must be "print" ..just for viewers who didn't notice.
***** For newbies this is a tough concept to grasp. Especially the for statement is confusing. You have to practice this concept to fully understand it.
If you have previous programming experience then it is easy, other wise it is hard. I have learned 2 and a half programming languages before so it is very easy for me.
One small advice to people, if you are just watching the videos, i think it would help if you have eclipse in the background and type out the code what bucky is doing and run the program yourself, in that way it gets less boring and you will be able to learn more as well as stick to the whole series, you would easily get bored if you prefer only watching these...
Thats what i do. I have two monitors, the main monitor has the tutorial running while my second has eclipse open in which im following along with the tutorial.
It's an argument that says "this function needs a nested array in order to work". It's a placeholder for you to send a nested array into that function. The "x" is just a generic name for that argument -- you could call it int potato [][] or int vietnameseProstitute [][] if you wanted. The brackets -- [] -- indicate it's an array. The number of bracket pairs indicate arrays nested inside of one another, like those Russian dolls you open up and find littler dolls in.
He use length, because the multi array does not have a "nxn" size or a "nxm" size, so the program must know until how far it goes in each row.As you can see, in the program, the "firstarray" has 2 rows and each row has 4 columns, a 2x4 size. But in the "secondarray" he has 3 rows but in the 1st and 2nd row are different number of columns, in the 1st are 4 columns meanwhile in the 2nd is just one. So that is why he needs to use the "length". I hope that this helps!
@HammockerSam This is because the 'row' in 'x[row]' is gonna increase with 1 in every loop, as you know increment. because the x basically has an array in an array, it means that the row (which starts at 0) is gonna calculate the length (as in 'x[row].length') of the first array, second array, or third array, depending on what the 'row' value is. Example in next comment (no space :P)
well, writing x[][] simply means that we are telling the system that we declared a two dimensional array, that is [] followed by [], we can also type in exactly how many rows or columns we need the system to allocate, like x[2][3], so yeah thats what it means :)
@ShaneCopseysTV Chill man, I didn't say they're not usefull, I said I dind't know how will they be usefull. Probably cause I've never tried to make a full program.... tht's why I'm here. Now I know one scenario thanks to you.
If I understand what you're saying correctly, then yes. Imagine a multi-dimensional array like a table. if we have the array called 'letters': a-b-c-d e-f-g-h i-j-k-l the character 'j' would be letters[2][1]. The first column is 0, the second 1, the third 2. 'h' would be letters[1][3].
correct me if im wrong guys based on my understanding on the loop statement bucky just made public static void display(int x[][]) then this programs expect an array for(int row = 0;row < x.length;row++){ for(int column = 0; column < x[row].length;column++){ System.out.print(x[row][column]+"\t"); } System.out.println(); by the way int x represent the 1st array list as a sample for the 1st loop says int row will get every array that there is by 1 in length after the loop is done now our row have a value then proceed to next step then for the nested loop which is column if column is less than x[row].length which our row with the list of array in length remember we have 2 array index in our first array so after getting the 1st index and the 2nd we tell the program to System.out.print(x[row][column]+"\t"); then System.out.println(); did i get it right?
The "(int x[][])" means that, when you run the method, you can't just type, "display()", you have to add an integer multidimensional array in the parentheses.
can anyone please tell me what the problem is, i got the output in my console with this pattern: This is the firstarray 2 4 6 8 10 12 14 16 This is the secondarray 31 32 33 34 45 22 23 12 i did the same thing as bucky did in the tutorial. hope u can help me guys thanks!
can anyone tell me what is/are the error/s with this one? class apples { public static void main(String args[]) { int firstarray[][]={{2,4,6,8},{10,12,14,16}}; int secondarray[][]={{31,32,33,34},{45},{22,23,12}}; System.out.println("This is the first array"); display(firstarray); System.out.println("This is the second array"); display(secondarray); } public static void display(int x[][]){ for(int row=0;row
kinagatnang sevenlion check his code at line 16 and compare it to yours. he wrote System.out.print(x[row][column]+"\t"); but you wrote System.out.println(x[row][column]+"\t"); ..... "println" means each number/element will be printed on the next line, but "print" means each number will be printed on the same line. I hope this helps..
also, for your comment about the scanner and strings, you can't compare strings with the "=" sign. You can only use string.equals() or string.equalsIgnoreCase() to check for equality.
(int x[][]) specifies what sort of parameter you have to input into the method. Within that method, x is a placeholder name for the array you input. You could also have (double elephant), (String name), or even multiple parameters - (int x, int y, int z etc). Just say you made a method like so: public int calcAverage (int x[]){ int sum; for (int num : x) { sum += num; } return sum; } Then call the method within your main method...[contd]
the array is passed to the display method .... e.g. in the first main method the display method is called by typing "display(firstarray);" Then, the display method basically changes the name of the firstarray to x.... meaning that x[][] is a copy of the firstarray.... and then the second array when it is called
I need help. Can anyone explain me this line "for(int column = 0; column < x[row].length; column++)" ? The exact problem is that I do not understand what stands for x[row].length ???
X is just another name given for "first array" or "second array" (depending on which one you were doing). Saying you want to end the loop at the end of the values of x.[row] is another way of saying to loop through the columns
x[row].length is a length of particular 1D array within 2D array. I.e. if we have 2D array like: int blaster[][]={{23,24,36},{76,21},{67,84,75}}; x[0] is equivalent to {23, 24, 36} array. x[0].length would be length of that array. x[1].length would be length of {76, 21} array etc. He's using x[row].length to determine how much times he's going to loop over particular 1D array.
@stradoodle217 Declare the variables like so: String variablename[][]={{"nope"},{"no","naw"}, {"negative"}}; Don't forget that the S has to be in capital. Also, your display method will take in as argument a string, so it'll be something like: public static void display (String x[][]).
I believe that instantiating multidimensional arrays as: int firstarray[][] = {{1,2},{3,4}}; is discouraged. I think it is properly written as: int[][] firstArray = {{1,2},{3,4}};
Please follow Bucky's code accordingly, double check if the codes are exactly the same as bucky. What I think your problem is System.out.print(x[row][column]+"\t"); instead of System.out.println(x[row][column]+"\t"); take out the "ln" from the print. I hope my advise helps. Thank You
I just want to understand something please .. for(int column = 0; column < x[row].length; column++) Why did we wrote x[row].length and not x.length ? is not x[row].length is the same of the length of x ?
Memo Thunder the way I understood it is x.length is how many rows there is and x[row].length is the length of the specified row meaning how many columns it has
Memo Thunder exactly as zoranhacker said. Bucky doesn't explain why you don't want to do x.length, but I'm sure in a later tutorial he will explain it, but either way you know now :3
he's printing out the x[row][column]. So say for example, the first would print out x[0][0], so the zeroth(first) row and the first number in that row. In the next iteration, it would be x[0][1], so the second number in that row. Then when it finishes that statement, the first loop iterates and it becomes x[1][0], so the second row, first column. then x[1][1], and so on. if you need more help, feel free to let me know :D
I think its similar to the C++ term "pass by reference". Basically its like the format for when use the method, you need to pass this and only this format into the method for it to work correctly. so the "x" is the variable and the [] [] represents multi array. You need to pass into that method an array similar to that format.
usually you would know the number of columns for an array. Otherwise create a method called size to iterate through the rows and using .length add the number of columns together.
I love how helpful people are in the comment section. The comments in these tutorials are the least toxic I've seen in any youtube video.
+Villexy herp i was just thinking that
+Villexy herp I felt the same way too !!
smart people don't have time to troll, we're here to learn !Go smart people!
Yep, best comment section ever! Defiantly least toxic comments I've ever seen in any youtube channel before!
Programmers are nice people :)
oh really dod? pakyu
Think of this line of code as a type writer. I won't get to why it's like a type writer yet but bear with me:
This is the confusing part:
for (int row = 0; row
+Graver Thanks brother, much needed.
+Leonidas Davos No problem
+Graver thanks a lot mate
Thank you for this insightful comment really helped me understand what was going on!
Why does it do this part first
for(int column=0;column
Maybe people are failing to understand this easily because Bucky hasn't told us something which might seem obvious but people might not realize.
If u have a 2D Array, int arry[][] = { {1,2,3}, {4,5,6} };
arry.length = 2. Why? Because in the main array "Arry" There are 2 smaller arrays. That's why it will give you the number of arrays inside your array.
If you want to know the length of one of the smaller arrays inside Arry then you would have to do:
arry[0].length to know the length of the first smaller array (row). Why? Because 0 means the first as speaking in computer language.
arry[1].length would give u the length of the second smaller array or second row.
thnx i really needed it...
thank you made it much easier
lol. You didn't realize?? xD
Fuck you Robert Reimann
i'll use a single array for this..note(this is just my own way of doing it, there may be multiple easier ways)
int arr[] = {1,2,3,4,5};
for(int x = 0; x < arr.length; x ++)
{
// check if they have no remainder(i.e 0) when divided by 2
if(arr[x]%2 == 0)
{
System.out.println(arr[x]);
}
}
hope this helps :)
for those of you who have just lost your mind...
type this out, then think logically what the for loop column is doing, when it ends and what then happens to the for row loop...
the overall "x" part of it is applied to firstarray and second array when calling the "display" method (or whatever you called it)...
I really do hope this helps.
I'm up to the 51st Java tutorial now but if you had a memory like mine you will realise you can't just simply watch these videos and move on. I did just that the first time, got to the 50th tutorial and forgot everything in the earlier ones and had to constantly re-watch. This time around I'm taking notes, taking my time and making my own examples. I've learned MUCH more because of this new approach and have a higher understanding of how things work in Java.
have you finished the tutorial?
@@scooby-dooafterlife6969 oh, wow. Probably. I don't remember. LOL.
I now program using C# and Unity. Although I enjoy working with Unreal and Godot is also great for beginners.
@@odo432 good
god knows how many times you have helped students to pass their , tests , assignments , quiz and classworks ... you are a life saver
Remember cartesian plane math? this is exactly it. int a[][] is sam as a[x][y], x is horizontal and x is vertical. also bar graphs and line graphs, X and Y axis, Y is dependent on X. in this multidimensional array the column which is Y is dependent on X which is the row.
i wish my brain was bucky I would know every single thing he does tutorials on from physics to math to programming
Listen to the birds in the background, without the background noise it would be so peaceful, programming in the heart of the nature that is :D
I have to admit this is a much better way of going about it. I am simply writing out the code and trying to gain a rudimentary understanding but, once I get to about 40/50, I'm going to start again and take notes etc.
To be honest, I think doing what you did is the best method. The purpose of going over everything once is basically to help give you a bigger picture view of how Java works.. I will probably get to about 50 before going back and restarting. I won't remember much, but I'll have a much better understanding due to having gone over everything once before. It's hard to watch something for the first time and take notes. Much easier the second time around!
oh man i love you - thank you dude - I am in my second level Java class and I had problems with arays and multidimensional arrays - truly, you broke it down soooooooo easily. I wil follow you forever my man. Thanks again.
GW
Kennesaw State U.
Excellent teaching. Incredible that you did this in 2009 and yet, still so useful! Thank you!
Both. I build the program(s) in eclipse while watching the videos and pause to take notes. I have a really horrid memory so taking notes while building the program helps me remember and better understand what I am doing. It also helps when I wish to look over them in the future instead of having to rely on skipping through the videos and finding it.
Wuhuu, had a lil struggle understanding this at first, but after going through it one step at a time, it all makes perfect sense :D I bet you all know what kind of sensational feeling I'm talking about ^^ Thanks so much for these tuts Bucky :)
Can I hear birds tweeting in the background?
I read that as twerking for a second lol
yeah those are called twitters
man had to watch this many times to fully get it, but great tutorial
thank you all, sir and ma'am and Mr. Boston. You are all great teachers
Yo dawg, we put an array in your array so you can array while you array
Bucky is at the top of my list for tutorials. A text version of this is H&L uk google it its awsome equivalent to Bucky. Books 1st Beginer Java for dummies then head first java and then java patterns. Start with Bucky. Important to use all resources even if your going over the same material especially if your going over the same material Bucky dosent explain everything. But does the best vid tutorials in my opinion.
i can't find java patterns in google, can you name the book more precisely?
Head Start Pattern and for You tube check out Derek bana java he really covers a lot.
thanks, i'll check that out
Head First Java is a great book for beginners in Java :)
i took java introduction to programming it went great and finished
but i wanted to expend my knowledge and got here
i really enjoy your videos thanks for the help!
You're a great teacher, thank you for this!
@HammockerSam
Better explenation (soz for bad explanation in earlier posts):
Your in the first for loop: row = 0;
Your in for loop in the for loop: row still 0 because it hasn't incremented yet;
at that moment x[row].length equals x[0].length, which means, the length of the numbers that are in the first array. Now it has that number (for example 10) it knows that it should make that many colums.
after that it's gonna restart the loop, and this will go on until row
since x is a multidimensional array, x.length refers to how many arrays are in x. In the case of {{1,2,3},{4,5,6}} x.length would be 2
(0 and 1) because there are two arrays. x[row].length refers to how many numbers are in an array in a multidimensional array. Hope this helps!
These videos are all delicious! They keep getting better. I think you've made a programmer out of me, Bucky. I also love how you just throw the code out there while you are teaching. It is so easy to understand that way. P.s keep making reusable code like this that passes things to methods to be processed. Me gusta.
-> Loopception, Taking notes is something nobody likes to do, but you are right it is necessary. I knew that I should have been taking notes by Lec. 3. Here I am on 34. I have written four small Java programs by now and I still have to refer back to things as simple as the for loop video, to get any thing done. I think that i am going to backtrack tomorrow and jot down the highlights. That way I do not get any further behind. BTW, I am in a Java class in college. Bucky is better.
Bucky, do not understand this the wrong way. But you are my hero.
Thank you.
u got talent in explaining, quality info packed in a minor time frame, keep it up mate)
I wasn't doing it until ep 30 where i got confused and started all over again :S now its waaay easier to understand.
The int x[][], as far as I understood, is simply to tell what kind of method you're going to use. You can later use that method to place any multi dimensional array in there, so it will place your array values in the x[][]= method. When you look at for example "display(firstarray);".. it just takes the values of the firstarray and places it in the display method, so x[][] will equal exactly what your firstarray equals. It will do the method calculations and display it in a modified style.
5:38 I can hear birds singing, awesome!
Very nice video. I have a test tomorrow and it helped me understand better about looping through 2d array in Java.
What Krazy92 said. The reason it saves us time is that it means we don't have to write out a new piece of code every time we want to print an array. If you have 100 arrays and you want to print them all out, it's easier to type:
display(array1);
display(array2);
etc.
...rather than typing out two for loops and a few print statements every time.
Thanks dude your explanations on MultiDimArrays was elightening!
wonderful, i never understood mulitdimintional array before, thanks bucky
love you Bucky.because of u I am understanding how to print multidimensional array
@HammockerSam
Example:
Your in the loop for the first time, so row=0.
that means that it's gonna look at x[0] (in this case so it's gonna look at the length of the first array in the multidimensional array (array in array) that you send to the method as x value) Then the method .length will calculate the length of the array, so x[0] will look how many numbers are in the first array of the array, and this is necessary since it needs to know how many numbers to print.
Good thing I'm taking notes and taking my time. I wouldn't understand this if I didn't. 7 minute tutorial in 30-40 minutes lol.
The x.length means you're getting the length of the x so in this case for the first array the length of x is 2 because we have two rows. For the second array the length of x is 3 because we have three rows. The x[row].length means you're getting the length of x[row] so for the first loop, it gets the length of x[0], for the second loop, it gets the length of x[1] and so on if there's more than one column in that row. In short x[row].length is used to know the length of column in that row.
Thanks lol helps! TO ALL: IF YOU TYPE syso AND PRESS CTRL AND SPACE AT THE SAME TIME, IT WILL TYPE System.out.println(); FOR YOU ;)
That was amazinggggggggggggg ..thumbs up Bucky!
Irrespective of what IDE you use the array elements must be dislplayed in different lines. Because we added an empty line statement : System.out.println(); after the column for loop. you might have forgotten to add this line if you arent getting the rows in separate lines.
Starting to get harder :D
probably have to see some of the videos twice to understand and remember it;)
great tutorials!
why thenewboston is far superior to school: the newboston has succeeded to teach 80,000 people things that school failed to teach about 30.
A couple good practice tips: Change your arrays and method to display strings instead of integers, and call the display method from a different class (I used the tuna class we created way back when).
say if string x = "x" and string y = "y", to compare the two for EXACTness, you would use:
if(x.equals(y)){}
the above would be case sensitive, and if you don't want it to be case sensitive, you can use this:
if(x.equalsIgnoreCase(y){}
hope this helps!
bucky thanks that's sooo helpfull ..just one note ..for method Display Line 16..exact..[System.out.print(x[row][column]+"\t");]
U didn't mention that "println" must be "print" ..just for viewers who didn't notice.
you saved me!! lol
literally you have been helping me pass comp sci LOL
This was Bucky's most confusing tutorial so far! :(
I am looking forward!! :)
***** For newbies this is a tough concept to grasp. Especially the for statement is confusing. You have to practice this concept to fully understand it.
If you have previous programming experience then it is easy, other wise it is hard. I have learned 2 and a half programming languages before so it is very easy for me.
PigKing107 And a half? lol
Looking back, I can't believe I thought this was "confusing". I was such a noob then..
No. x.length refers to the number of rows, and x[row].length refers to the number of elements in the specified row.
before today I always found multi dimensional array complicated !!
buck u rock !!
x.length means the length of the array. You can write it as row
One small advice to people, if you are just watching the videos, i think it would help if you have eclipse in the background and type out the code what bucky is doing and run the program yourself, in that way it gets less boring and you will be able to learn more as well as stick to the whole series, you would easily get bored if you prefer only watching these...
Thats what i do. I have two monitors, the main monitor has the tutorial running while my second has eclipse open in which im following along with the tutorial.
It's an argument that says "this function needs a nested array in order to work". It's a placeholder for you to send a nested array into that function. The "x" is just a generic name for that argument -- you could call it int potato [][] or int vietnameseProstitute [][] if you wanted. The brackets -- [] -- indicate it's an array. The number of bracket pairs indicate arrays nested inside of one another, like those Russian dolls you open up and find littler dolls in.
He use length, because the multi array does not have a "nxn" size or a "nxm" size, so the program must know until how far it goes in each row.As you can see, in the program, the "firstarray" has 2 rows and each row has 4 columns, a 2x4 size. But in the "secondarray" he has 3 rows but in the 1st and 2nd row are different number of columns, in the 1st are 4 columns meanwhile in the 2nd is just one. So that is why he needs to use the "length".
I hope that this helps!
I like your java tutorials, Bucky. I learned a lot.
@HammockerSam This is because the 'row' in 'x[row]' is gonna increase with 1 in every loop, as you know increment. because the x basically has an array in an array, it means that the row (which starts at 0) is gonna calculate the length (as in 'x[row].length') of the first array, second array, or third array, depending on what the 'row' value is.
Example in next comment (no space :P)
Hey bucky, knock knock (who's there?)
You are bucky, you're always there for my Java learning :-)
i wish you lots of luck bud, these tutorials are phat!!
well, writing x[][] simply means that we are telling the system that we declared a two dimensional array, that is [] followed by [], we can also type in exactly how many rows or columns we need the system to allocate, like x[2][3], so yeah thats what it means :)
ya i figured that out as I progressed,,,Arrays and lists are discussed in Detail in his Intermediate tutorials,,thanks
@ShaneCopseysTV Chill man, I didn't say they're not usefull, I said I dind't know how will they be usefull. Probably cause I've never tried to make a full program.... tht's why I'm here.
Now I know one scenario thanks to you.
@LeloDelatino this concept is just so full of win
Love the chirping birds in the background!
Very happy by learning this lesson ! many thanks
Thanks this really cleared up my doubts, your tutorials are awesome! Keep it up!
Thanks, ya did a helluva lot better of a job explaining this than my lecturer did!
If I understand what you're saying correctly, then yes. Imagine a multi-dimensional array like a table.
if we have the array called 'letters':
a-b-c-d
e-f-g-h
i-j-k-l
the character 'j' would be letters[2][1]. The first column is 0, the second 1, the third 2. 'h' would be letters[1][3].
correct me if im wrong guys based on my understanding
on the loop statement
bucky just made public static void display(int x[][]) then this programs expect an array
for(int row = 0;row < x.length;row++){
for(int column = 0; column < x[row].length;column++){
System.out.print(x[row][column]+"\t");
}
System.out.println();
by the way int x represent the 1st array list as a sample
for the 1st loop says int row will get every array that there is by 1 in length
after the loop is done now our row have a value then proceed to next step
then for the nested loop which is column if column is less than x[row].length
which our row with the list of array in length remember we have 2 array index in our first array so after getting the 1st index and the 2nd we tell the program to
System.out.print(x[row][column]+"\t");
then
System.out.println();
did i get it right?
The "(int x[][])" means that, when you run the method, you can't just type, "display()", you have to add an integer multidimensional array in the parentheses.
can anyone please tell me what the problem is, i got the output in my console with this pattern:
This is the firstarray
2
4
6
8
10
12
14
16
This is the secondarray
31
32
33
34
45
22
23
12
i did the same thing as bucky did in the tutorial. hope u can help me guys thanks!
can anyone tell me what is/are the error/s with this one?
class apples {
public static void main(String args[]) {
int firstarray[][]={{2,4,6,8},{10,12,14,16}};
int secondarray[][]={{31,32,33,34},{45},{22,23,12}};
System.out.println("This is the first array");
display(firstarray);
System.out.println("This is the second array");
display(secondarray);
}
public static void display(int x[][]){
for(int row=0;row
kinagatnang sevenlion I have the same
kinagatnang sevenlion check his code at line 16 and compare it to yours. he wrote System.out.print(x[row][column]+"\t"); but you wrote System.out.println(x[row][column]+"\t"); ..... "println" means each number/element will be printed on the next line, but "print" means each number will be printed on the same line. I hope this helps..
lx natsu xl yeah it works. thanks for the help! hope i can ask u more questions about java coz i like to learn more about it but anyway thanks a lot.
lx natsu xl thnx alot
First for loop counts how many arrays you have (making the index)
Second for loop processes the numbers in each array
also, for your comment about the scanner and strings, you can't compare strings with the "=" sign. You can only use string.equals() or string.equalsIgnoreCase() to check for equality.
x.length gives the number of rows in the matrix
x[row].length gives the number of elements in a particular row
is your window open? i hear birds chirping.
i haven't been outside in days.
wait for 2020. you will wont be outside for ages
thank you !!!!
that was very Helpful to me
if row's index is 3 i mean when row=3 (so it has 4 elements) the column
thanks a million , best tutorial possible !
Hello Bucky.
Wouldn't you make a tutorial video of how to make an integral image (well, I mean table of an original table)?
public static void display2DArray(int[][] array) {
for(int[] x: array) {
for(int y: x) {
System.out.print(y+"\t");
}
System.out.print("
");
}
}
More compact and effecient
public static void display2DArray(int[][] array) {
Arrays.stream(array).forEach(ar -> {
Arrays.stream(ar).forEach(v -> System.out.print(v + "\t"));
System.out.println("
");
});
}
GET REKT M8! :D
(int x[][]) specifies what sort of parameter you have to input into the method.
Within that method, x is a placeholder name for the array you input. You could also have (double elephant), (String name), or even multiple parameters -
(int x, int y, int z etc).
Just say you made a method like so:
public int calcAverage (int x[]){
int sum;
for (int num : x) {
sum += num;
}
return sum;
}
Then call the method within your main method...[contd]
the array is passed to the display method ....
e.g. in the first main method the display method is called by typing "display(firstarray);"
Then, the display method basically changes the name of the firstarray to x.... meaning that x[][] is a copy of the firstarray.... and then the second array when it is called
I need help. Can anyone explain me this line
"for(int column = 0; column < x[row].length; column++)" ? The exact problem is that I do not understand what stands for x[row].length ???
x[row].length is the length of the row
X is just another name given for "first array" or "second array" (depending on which one you were doing). Saying you want to end the loop at the end of the values of x.[row] is another way of saying to loop through the columns
+Jay Bartgis I would just like to thank you for being so supportive in the comments section, you have been helpful to me ever since the first ep 😂
x[row].length is a length of particular 1D array within 2D array.
I.e. if we have 2D array like: int blaster[][]={{23,24,36},{76,21},{67,84,75}};
x[0] is equivalent to {23, 24, 36} array.
x[0].length would be length of that array.
x[1].length would be length of {76, 21} array etc.
He's using x[row].length to determine how much times he's going to loop over particular 1D array.
Lazic B. really good answer.
@stradoodle217 Declare the variables like so: String variablename[][]={{"nope"},{"no","naw"}, {"negative"}};
Don't forget that the S has to be in capital. Also, your display method will take in as argument a string, so it'll be something like: public static void display (String x[][]).
@14koder It's called a nested for loop.
I believe that instantiating multidimensional arrays as: int firstarray[][] = {{1,2},{3,4}};
is discouraged. I think it is properly written as: int[][] firstArray = {{1,2},{3,4}};
Amazing video! This has helped me sooo much :)
@ Treeky in the display method change to print.
they can be used in games to store multiple values and can be used by typing one word in the script
Watched this video 5 weeks ago and understood nothing. Began from beginning now, and now I understand!
Please follow Bucky's code accordingly, double check if the codes are exactly the same as bucky. What I think your problem is
System.out.print(x[row][column]+"\t");
instead of
System.out.println(x[row][column]+"\t");
take out the "ln" from the print.
I hope my advise helps.
Thank You
I just want to understand something please ..
for(int column = 0; column < x[row].length; column++)
Why did we wrote x[row].length and not x.length ? is not x[row].length is the same of the length of x ?
Memo Thunder the way I understood it is x.length is how many rows there is and x[row].length is the length of the specified row meaning how many columns it has
zoranhacker Yeah after playing with it for a bit I came to the same conclusion.
Memo Thunder exactly as zoranhacker said. Bucky doesn't explain why you don't want to do x.length, but I'm sure in a later tutorial he will explain it, but either way you know now :3
Started 2 days ago, already on episode 34. And i gotta' tell you, its going pretty well.
EXCEPT FOR ARRAYS. I can't stand them.
Yay! I don't know about you guys, but I'm finding this Java stuff pretty easy. Hehe, maybe it's just Bucky.
Thanks man! Great tutorials ! Helped me a lot..
@aiwasen .length is a outside class method for the array. The dot is calling it.
he's printing out the x[row][column]. So say for example, the first would print out x[0][0], so the zeroth(first) row and the first number in that row. In the next iteration, it would be x[0][1], so the second number in that row. Then when it finishes that statement, the first loop iterates and it becomes x[1][0], so the second row, first column. then x[1][1], and so on. if you need more help, feel free to let me know :D
I think its similar to the C++ term "pass by reference". Basically its like the format for when use the method, you need to pass this and only this format into the method for it to work correctly. so the "x" is the variable and the [] [] represents multi array. You need to pass into that method an array similar to that format.
usually you would know the number of columns for an array.
Otherwise create a method called size to iterate through the rows and using .length add the number of columns together.
Getting harder and harder but I'm not going to give up!