본문 바로가기

DEMO CODE/JAVA 기초

[JAVA] Ex006 다중for문, if 예제

반응형

/*

* 2g, 3g, 5g의 돌이 각각 10개씩 있다. 

* 이 돌들의 조합으로 71g을 만들려고 한다. 

*/

public class Dol2g3g5g {

public static void main(String[] args) {

for(int five=0;five<11;five++){

for(int three=0;three<11;three++){

for(int two=0;two<11;two++){

if(5*five+3*three+2*two==71){

String str=String.format("5g: %d개, 3g: %d개, 2g: %d개%n",five,three,two);

System.out.printf(str);

}

}

}

}

}

}

반응형