알고리즘
1~10까지 더하는 알고리즘
개발 초보
2023. 3. 31. 13:33
public int oneToTenAdd(){
int i = 1;
int j = 0;
while(i < 11){
j = j + i;
i++;
}
return j;
}
아래는 eclipse IDE에서 구현한 것이다.
package algorithm;
public class Algorithm {
public void oneToTenAdd(){
int i = 1;
int j = 0;
while(i < 11){
j = j + i;
i++;
}
System.out.println(j);
}
public static void main(String[] args) {
Algorithm getResult = new algorithm();
getResult.oneToTenAdd();
}
}
결과:
