Search

for

public class Ex12_For { public static void main(String[] args) { // for( 1์ดˆ๊ธฐ์‹ ; 2์กฐ๊ฑด์‹ ; 4์ฆ๊ฐ์‹ ) { 3์‹คํ–‰๋ฌธ } // -์‹คํ–‰ ์ˆœ์„œ : 1 โ†’ ๋ฐ˜๋ณต(2 โ†’ 3 โ†’ 4) // 1. 1~10 ๊นŒ์ง€ ์ •์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค. for (int i = 1; i <= 10; i++) { System.out.print(i + " "); } System.out.println(); // 2. 50~100 ๊นŒ์ง€ ์ •์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค. for (int i = 50; i <= 100; i++) { System.out.print(i + " "); // 10๊ฐœ์”ฉ ๊ฐœํ–‰(์—”ํ„ฐ)ํ•˜์—ฌ ์ถœ๋ ฅ if( (i+1) % 10 == 0 ) System.out.println(); } System.out.println(); // 3. 1~20 ๊นŒ์ง€ ์ •์ˆ˜ ์ค‘ ์ง์ˆ˜๋งŒ ์ถœ๋ ฅํ•˜์‹œ์˜ค. for (int i = 2; i <= 20 ; i+=2) { System.out.print(i + " "); } System.out.println(); // 4. 1~20 ๊นŒ์ง€์˜ ์ •์ˆ˜ ์ค‘ ํ™€์ˆ˜๋งŒ ์ถœ๋ ฅํ•˜์‹œ์˜ค. for (int i = 1; i <= 20 ; i+=2) { System.out.print(i + " "); } System.out.println(); } }
Java
๋ณต์‚ฌ