Nested For Loop In Java Tutorial #24
HTML-код
- Опубликовано: 7 сен 2024
- $1,000 OFF ANY Springboard Tech Bootcamps with my code ALEXLEE. See if you qualify for the JOB GUARANTEE! 👉 bit.ly/3HX970h
The nested for loop in java is just a for loop inside of a for loop. A common way to use a nested for loop in java is to get elements from a 2d array. To do that, your outer for loops takes care of the rows and your inner for loop takes care of the columns.
Java loops can be VERY tricky, but don't worry too much about it right now! Use the code I provided and after time you'll get the hang of java loops :) If you followed along, congrats! You learned-by-doing!
I hope you enjoyed this nested for loop in java tutorial! I like to have a nice mix of tutorials and actual projects for you all :)
🌅 Source Code - github.com/ale...
Do you want to learn how to code from scratch, in Java? Check out my Java Tutorial For Beginners: • Coding For Beginners I...
How are you using nested for loops in java? -
Full Java Tutorial For Beginners Playlist: • Full Java Course by Al...
Free Tips: bit.ly/3U6HXcb
Disclosure: The Springboard link provided is linked to my affiliate account & supports the channel.
~
Alex Lee
If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h
I didn't pay attention in my java class and now this guy saved my life
nice
At least you had a java class, all I have is stupid Pseudo code and a lab.
@@kevinburns8473 nice
@@kevinburns8473 u shuck
@@gamingwithronpubgm3615 yeah no kidding 😂
This guy the GOAT, best tutorials I've seen
🐐
If you have an array with different dimmensions try:
for(int i =0; i< array.lenght; i++) {
for(int j =0; j< array[0].length; j++) {
}
}
This will go through all values in array that is or isnt square
This is a great tip! Also just in case you have a different number of items in each row, you could improve upon this by checking the length of each row:
for (int i = 0; i < array.length; i++)
for (int j = 0; j < array[i].length; j++)
System.out.println(array[i][j]);
Alex, people like me need your videos! Whenever I am confused about anything or need an explanation I can understand I can always count on you. Please never stop making videos!
I had no idea what we were doing in class today, thanks for the help!
nice
Myself in APCSA class, first time student come from India to US of A, my first teacher Sridhar Kandukari very smart man, he help me now u teach me, very nice sir, vineeth kandukuri also likes ur teachigg always watches video with fav lemon pickle recipe from vah chef
nice
Ah im telling you im gonna fall in love with this guy HAHA
What a life saver hahaahsha thanks man!
Thanks for explaining clearly, this nested is so hard for me at starting 2 months at coding. Nested and array are so difficult.
Good thing i ran to your videos while learning java , the old concept i learned in cpllege are now cleaner, good job Alex.
hey I think u teach better than others , esp in explaining the nested loops topic , listing all i and j
This videos are incredible! I cannot understand what my Java teacher says for the life of me but this makes so much sense! Thank you!
Man, I really was blown away by this amazing tutorial on nested loops! It's sooo damn good! Also I love how easy you explained how to use it to print 2D arrays.
Thank you so so much! 🥰
I'm using it for an assingment, this really gave me the basis of Nested For Loops. I'm using to create the infamous create words out of phone numbers ie: 2 = ABC, so there is about 2143 different combinations for a 7 digit phone number, and I'm going to use for loops to help with this, I hope. Almost forgot the 2D arrays video also helped in using [ ][ ]{"A", "B", "C"},{"D ", "E ", "F "}, etc. Thank you again!
Turquoise*
All secondary colors of light are combinations of the primary colors: Red, Green and Blue. However, the third secondary color of light is Yellow. That's what you get when you combine Green and Red.
Color and spelling aside, thank you for taking the time to create these videos and for launching your own coding community. I joined the Discord and found the links there very helpful.
Kustos that’s great thank you!
@@alexlorenlee just remember there's no word in the english language, where the letter U doesnt follow Q ;) (ie: queen, quack, etc.)
@@sabrinakomm750 there are many... //when you play scrabble too much...lol
Making for loops to find perfect numbers from 1-10000 First intro programming class this shit helped a lot
dude i have an exam on nested loops in like 1 hour and you just saved my ass thank you so much
It's good, easy to understand. Thanks!
Ming Chen I’m happy it helped you!
i recently start learning java online to get a job, i do have teacher to teach me but i never understand what he is saying till , but the good things i found your videos on youTube and your way to teach is amazing, you are amazing.
are you a programmer now?
Your teaching style is literally very good your videos deserve to be viral in india i tried my best to share your teaching 😊
Little suggestions: take ur course to udemy
Best java tutorials on youtube!!
This guy is literally teaching me Java more the paid courses very good explaining and makes everything simple a lot of people owe this guy honestly !!
I'm using nested for loops for a class assignment. We are given a number of rows and columns. Rows are integers and columns are alphabetical. so the output should list something like this //row1 1A 1B 1C //row2 2A 2B 2C and so on. Pretty difficult for an online class but your videos help a lot. Thanks!
Great vid! Super helpful! You are awesome!
Since you asked, I'm learning about nested for loops because they're one of the key concepts to get your head around if you want to reach a higher level of programming (in my opinion).
Furthermore, I would say that nested for loops and nested while loops open up a lot more possibilities - so thanks a lot for this very explanatory video!
I had to check the date on the video when I saw the keyboard he is using
just want this dude to know I’m passing ap comp sci because of him
Me too I’ve been winging it for weeks now with no idea how to use for loops thank god for Alex lol
If you do :
" System.out.println(ArrayName[i].length); ' before nested loop,
It print's out ..I think the Address of the row before printing it's entries !! Which was very helpfu to me, for understanding what it was actually doing!
when I get a problem in a code, all I need is to check your channel. thank you
Thank you so much! It breaks down simple concepts for easier understanding
I absolutely LOVE these! Easy to understand, to the point and helpful. Thanks a lot, Lee!
Hey Alex, you're making it a bit too easy.
AND I LIKE IT!!!
Good job man one of the best tutorials I've seen
Thanks for this video! I understand for loops so much better and when I go through an array. Studying for a test and didn't quite understand this portion.
Eternity Studios great!
you made it so much easier to me to understand and i hope to pass my test with a great mark😩❤️
can you make one more video on Multi-Dimensional Arrays,
to be more specific on " HOW TO VISUALIZE A TABLE MADE using 2d Arrays" ;
it will be such a relief if i get my doubts clear on that topic
please!!
I'm currently studying at a bootcamp to be a QA Engineer, and we have been learning these during Java Classes. I watch your videos to recap, and It's SUPER beneficial
Thanks man I’m in a AP CSA class and you’re clarifying how this works for me and helping me understand better
Completed Playlist- Java Basics 2 Good videos thanks Alex!
Alex please make a video on pattern program with nested for loops
bubble channel
for(int i = 0; i < 7;i++){
for(int j = 0; j < i;j++){
System.out.print("*");
}
System.out.println();
}
Output:
*
**
***
****
*****
******
Explanation: outer loops executes until the condition is met(i = 7),
The inner loop executes while j is less than i
When i = 0
J = 0
Increment i to 1
Now the second time through the loop
I = 1
j = 0
0 is less than one so print an * , increment j to 1 and check the condition again
1 isn’t less than 1 so we exit that loop and print an empty space,
Now i = 2
J = 0
0 is less than 2 so we print *
I is still 2
But now we increment j
J = 1
1 is less than 2 so we print another *
So far the sequence is
*
**
J is now incremented to 2
Now we check to see if j < i (2
Dziękujemy za zrobienie tego i innych samouczków java!
QOTD... I’m using nested inside nested loops to run a simple word game for kids. I’m still wrapping my head around what I want to accomplish and the logic behind putting together the code to make it happen.
Thank you so much for your help! I was using this video to learn how to loop through 2D Arrays.
This is my first time watching one of your videos, but I have a feeling that I am gonna watch a lot more this year!
I know it's a 5 year old video, but for anyone watching now, it's spelled "Turquoise", and if you use intellij, it has an autocorrect feature
I can’t say thanks enough ❤️❤️
thank youuu!!!! 🙇🏻♂️ now it's clear to me how nested for loops are for 2D arrays 😁 thanks a lot!!!! 🖤🖤🖤
this is very helpful! so happy that i found your channel:)
BATOOL xx I’m glad you found my channel too! Thank you!
I just like how you use real world examples out there present in the world .... That clears concepts better
After watch so many videos, thanks to this one i finally understand it... Thank you!!!
simple tutorial ezzzz java , thanx man
Alex you must be an angel in disguise... Thank you thank you thank you soooo much because I thought that I’d never understand this! I’m really happy right now!!
nice
Thanks bro!!!! I had a lot of confusion but you helped me understand it easily.
Seeing this video for learning purpose. I appreciate your efforts. Keep it UP!!
Next time can you please do a video on nested for loop example questions and go through them? It will be very helpful since I've been having trouble in computer science class
everything is great .Thank you Alex! I think Length method would be more easier because sometimes we can have a lot of rows and column
Thank you Alex!, watched so many videos but only understood after your video. It was a great help. Please make videos on Sorting and Searching Algorithms in java. Waiting for those videos.
I use 'nested for loops' for number patterns in school. If you make a video on it, it'll be pretty cool!
Thanks for the great tutorials!
quick question, what is the benefit of doing a 2d array instead of just making a longer normal array? For example, { red, blue, green} {yellow, orange, red} can just be {red, blue, green, yellow, orange, red} and when you want to get an element you can just say colour[2] instead of colour[0] [2].
Wow you deserve so much more views and subs !
Thank you so much. You are really a awesome teacher.
thank you!!
Thanks man, do you have a video on sorting, searching, and recursion
Jairo Poveda not yet, but I probably will in the future
it helped me with my assignment thanku
Thank you for sharing your knowledge!You are the best!
Alex , I think these nested loops can also be used for a 3d array LiKE This :-
public class NestedForLoops {
public static void main(String[] args) {
String[][][] Array = {{{"Hi" , "Hello" , "Hey"},{"Bye" , "BabBye" , "Bye-Bye"}}};
for(int i = 0 ; i < 2 ; i++) {
for(int j = 0 ; j < 3 ; j++) {
for(int k = 0 ; k < 3 ; k++) {
System.out.println(Array[i][j][k]);
}
}
}
}
}
Got a nested loops quiz tomorrow and this video is teaching me for it 😂
Best video opening ever!
Your videos are so helpful I learnt oop following your video. Thanks a lot !
I think it is much easier to explain this using regular array syntax instead of the curly braces shortcut
First thing's first cool video and thanks for the help. We had to use nested for loops to create scenes like
1
12
123
1234
12345
123456
and so on and so forth. I guess this is pretty basic but I also practiced 2d arrays with it.
I am learning this in my programming I class.
Hey Alex :) In your 2d array - you write for (int i = 0; i < 2 ; i++) - why dont it go out of bounds, seeing that there are only 2 rows? 0 and 1
Thanks man. Studying these in advance because my prof is really a terror. Sure, he teaches well. But I feel so scared of him and he makes us do live coding in front(he's a very traditional prof). I'm a slow learner too so I might as well self study via RUclips, Google or any sources outside of school in advance.
Artillerist X Duelist great idea, that’s exactly what I went through too :/
Anyone just starting this, I found that the best way to organize my code within one file is to create a new method for each video, that way I can scroll down for easy review.
Hello Alex !
I can't understand this part:
String[][] fancyColors = { { "Red", "Blue", "Green" }, { "Cyan", "Magenta", "Turqiouse" } };
for (int row = 0; row < 2; row++) {
for (int column = 0; column < 3; column++) {
System.out.println(fancyColors[row][column]);
}
}
Can you explain to me please why in the second loop is "column < 3" and in the forst loop it is "row < 2" ? Because in the both arrays we have 3 elements. Thanks in advance !
Hey Alex,
first of all, your tutorials are great! One question, do you recommend any books for java programming?
Thanks in advance :)
Best regards
Java How to Program; Deitel & Deitel
Thank you for the help! Amazing content!
Thank you lex for the video you shared I learned a lot with your videos especially we are creating chatbot I used some of codes from you
Thank you Alex! Cool video
and cool music!!!
How would you make a nested for loop for a 2D Array if you do not know the row and column length?
Very helpful sir.....Sir can you do one where you have to calculate the average of 3 numbers using nested for loop using java coding
Im using nested for loops for making triangular hash pyramid 👀 @alex lee
Thanks for the tutorials but the music bg is too loudddd..! :))
you are A legend
To understand more regarding these loops 😁
Hey man, can you make a video on do-while loops? I'm working on a project for sh**s and giggles and cont seem to get the loop to work properly.
Kitchen Table sure! I have videos planned for a few weeks, but I’ll do while loops after that. I can help you now, and I’ll see if I can give you some advice
@@alexlorenlee that would be awesome. I'm basically working on a "guess the number" game for practice, that all runs in a do/while loop. is there some way I can send you the code or something?
Kitchen Table yea! Send it to my email alexlorenlee@gmail.com and I’ll get your code working
Holy shit it's making sense
Thanks Alex!
@ 9:00
Wouldn't it run 36 times since they're(i & j) less than(
_BlueBlazing_ great question! At first glance it looks like it would, but since we set i to 0, it includes 0, totaling to 5 and 10
hi Alex just started watching ur vids....do u do videos of html css and JavaScript?
Hi Alex, I like your videos a lot. I'm having a class presentation coming soon, and would like to ask you what recording software you are using? Your videos are all crystal clear and the layout is also nice. Thank you in advance.
Any vid software will work, you need to,set it in 720p and up for better resolution and quality,,but it takes a lot of File size
@@SkyeVintorez Thanks Jefferson, I end up going with OBS.
Thank you ,Alex!
Thanks Alex
Thank you and it is very clear,
I just have a question, what if the rows and columns elements were not the same length,
when I try it, I get errors with missing output, so how to print it all with no errors?
i have to make an 8x8 alternate 0's and 1's like
01010101
10101010...
for my final exam and its due tmr💀💀
this vid helped me clear up my understanding of nested loops but i still dont know what to do for the alternating thing🙃
turquoise :)
turquoise lol. you are a star Alex
I'm using nested for loops for a CS assignment :/
plz show how to save it and where will be that save code
Thank you Alex
this is fantastic thank you alex