Archives
Recent Posts
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
11번가
Today
Total
05-19 20:13
관리 메뉴

smwhee

[코딩도장_문제5] Multiples of 3 and 5 본문

Development

[코딩도장_문제5] Multiples of 3 and 5

smwhee 2017. 9. 15. 11:44

package codingDojang;


import java.util.stream.IntStream;


/*

 * Multiples of 3 and 5

 * 

 * 10 미만의 자연수에서 3과 5의 배수를 구하면 3, 5, 6, 9이다.

 * 이들의 총합은 23이다.

 * 1000 미만의 자연수에서 3, 5의 배수의 총합을 구하라.

 */


public class Question_005 {


public static void main(String[] args) {

int max = 1000;

int sum = 0;

String str = "012abc";

for (int i = 1; i < max; i++) {

if (i % 3 == 0 || i % 5 == 0) {

sum += i;

}

}

char[] ca = str.toCharArray();

int len = str.lastIndexOf("a");

System.out.println(len);

}

}

Comments