728x90
1. while 문
public class chp4_5_1_while {
public static void main(String[] args) throws java.io.IOException{
int s=1, i=1;
int n = System.in.read() - '0';
while(i<=n) {
s = s * i;
++i;
}
System.out.println(s);
}
}
2. do while 문
public class chp4_5_1_do_while {
public static void main(String[] args) throws java.io.IOException{
int s=1, i=1;
int n = System.in.read() - '0';
do {
s = s * i;
++i;
} while(i<=n);
System.out.println(s);
}
}
반응형
'전.java' 카테고리의 다른 글
문자열에서 문자 'r' 위치 구하기 (0) | 2021.01.31 |
---|---|
char 형 배열 (for, while, do while 문) (0) | 2021.01.31 |
연도를 읽어 윤년인지를 판별하는 프로그램 (0) | 2021.01.31 |
반지름(r)을 읽어 공의 부피(V)와 표면적(S)을 구하는 프로그램 (0) | 2021.01.31 |
세 개의 저항값을 읽어 직렬로 연결된 회로의 저항과 병렬로 연결된 회로의 저항을 구하는 프로그램 (0) | 2021.01.31 |