import java.util.Scanner; public class Main { public static void main(String[] args) { // nested loops = a loop inside of a loop Scanner scanner = new Scanner(System.in); int rows; int columns; String symbol = ""; System.out.println("Enter # of rows: "); rows = scanner.nextInt(); System.out.println("Enter # of columns: "); columns = scanner.nextInt(); System.out.println("Enter symbol to use: "); symbol = scanner.next(); for(int i=1; i
@@armagedon3505 i guess you already found your answer. still leaving this comment for others to find out. the count starts from 0. hence when the row number will be entered 4, it will count 5. cause 0,1,2,3,4. He wanted the exact number 4. That's why he choose i=1. if you choose i=0, the row number for 4 row will be 3.
sorry for the late reply but next(); can only be used to input strings but not spaces, so if you want to input a word, you can use next(); nextLine(); can be used to input full lines and more than one word.It can read spaces as well. So, in the video, for example they used next(); to input the symbol as it is only on word(or character)
Great video. A clearer illustration of nested loops is a mechanical clock. The second hand ticks every second. The minute ticks every minute or every 60 ticks or 1 loop of the second hand. The same for the hour hand. A little modification I would suggest is to put the println() to the end instead of the start of the inner loop. for (int i = 1; i
How does this work? I can only imagine rows and columns leave an empty space in relation to user input. Thereafter the symbol can take the shape left by the user input. However, how does tha machine know that after the first row that we dont only want the first row to have 5 symbols? But it continuously does that downwards? Btw when we enter our number for the condition of "print" does this make and count space horizontally while the "println" counts and makes space vertically?
print does not create a new line so thats why it goes horizontal. As per your other question, the machine knows this because of the system.out.println so the machine first puts in the amount of the symbol you want per line then it creates another row(line) and simply does it over and over again until loop is finished
Thank you so much. I don't really understand how the nested loop works, I want to fully understand how the program creates rows and columns. by the next time I see my comment, this should be different. Thanks bro
Why we do no put a scanner.nextLine(); after rows = scanner.nextInt(); and columns = scanner.nextInt(); . Since scanner.nextInt() can only read integer and it won't escape the line, I am confused.
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
@@UltraSolarGod Scanner scanner = new Scanner(System.in); int rows; int columns; String symbol1 = ""; String symbol2 = ""; System.out.println("Enter # of rows: "); rows = scanner.nextInt(); System.out.println("Enter # of columns: "); columns = scanner.nextInt(); System.out.println("Enter first symbol to use: "); symbol1 = scanner.next(); System.out.println("Enter second symbol to use: "); symbol2 = scanner.next(); for(int i=1; i