본문 바로가기

(Pre-class)31

Star Pattern exercise // *// **// ***// ****for (int a = 4; a > 0; a--) { for (int b = 1; b // * // * * // * * * // * * * * // * * * // * * // * for (int a = 4; a > 0; a--) { for (int b = 1; b 0; a--) { for (int c = a; c 2025. 4. 3.
Nested for loops exercise // print following// 0 1 2// 0 1 2// 0 1 2 for (int a = 0; a // print following// *// **// ***// ****for (int a = 1; a // print following// *// ***// *****// *******// *********for (int a = 1; a // print following// ****// ***// **// *for (int a = 4; a > 0; a--) { for (int i = 0; i 2025. 4. 3.
Do-while loop? 1. Execute at least once before go thru the condition// Run once and repeat by condition// do { code to repeat } while (condition);// if the while condition is true, it will repeat unlimited, so BE CARFUL!// print Hi~!int count = 0;do { System.out.println("Hi~!"); count++;} while (count // Ordering menu programScanner sc = new Scanner(System.in);int choice;do { System.out.println("Choose the .. 2025. 4. 3.
For - If exercise // print the counting of the 5 times numbers from 1 ~ 100int count = 0;for(int i = 1; i // print as following :000111222for (int a = 0; a 2025. 4. 3.
Break and Continue? 1. Break = stop and go out of scope { } of the loop(for/while)// print 1 ~ 10 and break when u meet 7 times numberfor(int i = 1; i  2. Continue = skip and go next// print 1 ~ 100 and skip the numbers which are not the 3 times numbersfor(int i = 1; i 2025. 4. 2.
While loop? 1. Repeated pattern as For loop, but different structure...// (initial);// while (condition) { code to execute + (update);} // end of while// needed to put the update to avoid the unlimited loop***// print the total of all from 1 to 10int sum = 0;int num = 1;while (num // print 2 times tableint n = 2;int i = 1; while (i // print 1 ~ 9 times tablesint n = 2;while (n 2025. 4. 2.