1. 
public class Example {
public static void main(String[] args) {
int sum = 0;
for(int i=1; i<=100; i++) {
if(i%3 == 0) {
sum += i;
}
}
System.out.println("3의 배수의 합은: " + sum);
}
}
- 3의 배수를 찾기 위해 나머지 연산자 '%'를 사용
2.
public class Example {
public static void main(String[] args) {
while(true) {
int num1 = (int)(Math.random()*6)+1 ;
int num2 = (int)(Math.random()*6)+1 ;
System.out.println("(" + num1 + ", " + num2 + ")");
if((num1+num2) == 5) {
break;
}
}
}
}
- Math.random()은 0이상 1미만의 무작위 값을 생성하고 이를 6으로 곱한 뒤 1을 더해 1부터 6까지의 정수를 얻을 수 있음.
- 루프는 while(true) 내에서 동작함
3.
public class Example {
public static void main(String[] args) {
for(int x=1; x<=10; x++) {
for(int y=1; y<=10, y++) {
if ( (4*x+5*y) == 60 ) {
System.out.println("(" + x + ", " + y + ")");
}
}
}
}
}
- 이중 for 루프를 사용해 x와 y가 1부터 10까지의 모든 조합에 대해 방정식을 만족하는지 검사.