Jump to content

Anyone know of any good Java resources?

imreloadin

So I'm taking a Java programming class this semester and everything was going great until we got to nested loops. For some god forsaken reason I'm not putting the pieces together and was wondering if anyone had any handy Java references that could help me understand them?

 

It's my first time programming so things can be a little rocky sometimes for me xD

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm..have you tried pluralsight? There are great tutorials there.


What's your problem with nested loops?

Ryzen 5 1600 @ 3.9 Ghz  | Gigabyte AB350M Gaming 3 |  PaliT GTX 1050Ti  |  8gb Kingston HyperX Fury @ 2933 Mhz  |  Corsair CX550m  |  1 TB WD Blue HDD


Inside some old case I found lying around.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Free:

codecademy.com

https://www.codecademy.com/catalog/language/java

Don't bother with pro unless you REALLY want to. 

 

The way a nested loop works like this:
I'll use for loops.

 

for (int i = 0; i < 3; i++) //This is the for loop declaration. 
  /*
  int i = 0 declares an integer number and sets the value to zero. 
  i < 3 says "If this is true, do the code inside the following curly braces. 
  i++ says add 1 to the value of "i" and store it in the variable "i"
  */
{ //opening curly brace to i
  println("This is i loop number: " + i + "j does not exist here.");
  for (int j = 0; j < 3; j++) //This is the imbedded for loops. (I like for loops the most. You can use while if you want.
    /*
    int j = 0 declares a new integer number and sets the value to zero
    j < 3 says "If this is true, do the code inside the following curly braces.
    j++ says add 1 to the value of "j" and store it in the variable "j"
    */
    
  { //opening curly brace to j
  	println("This is j loop number: " + j + "This is the value of i" + i);
  } //closing curly brace to j
	
} //closing curly brace to i

This will be the output:

Quote

This is i loop number 0 j does not exist here

this is j loop number 0 this is the value of i 0

this is j loop number 1 this is the value of i 0

this is j loop number 2 this is the value of i 0

This is i loop number 1 j does not exist here

this is j loop number 0 this is the value of i 1

this is j loop number 1 this is the value of i 1

this is j loop number 2 this is the value of i 1

This is i loop number 2 j does not exist here

this is j loop number 0 this is the value of i 2

this is j loop number 1 this is the value of i 2

this is j loop number 2 this is the value of i 2

First for loop i starts and it creates the variable "i"

Second it goes and prints the line saying what value i has. 
third it starts the for loop with j and creates the variable "j"

Now it started the j for loop and must finish it before it can continue the i for loop. 

 

For a video explanation this one seems pretty good. I was hoping for something a bit more visual. It's the best from what I found after a quick "visual demonstration imbeded loop" you tube search. 

Spoiler

 

Edit:
The video is using python but it's basically the same thing just written a bit differently. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×