728x90
320x100
1.왼쪽 아래가 직각이등변삼각형 만들기
*
**
***
****
*****
package chap01;
import java.util.Scanner;
public class TriangleLB {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n;
System.out.println("왼쪽 아래가 직각인 이등변삼각형을 출력합니다.");
do{
System.out.print("몇 단 삼각형 입니까? : ");
n = scan.nextInt();
} while(n <= 0);
for (int i = 1; i <= n; i++){
for (int j = 1; j <= i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
2. 왼쪽 위가 직각인 이등변 삼각형 만들기
*****
****
***
**
*
package chap01;
public class practice14_2 {
//왼쪽 위가 직각인 이등변삼각형
static void triangleLU(int n){
for (int i = 1; i <= n; i++){
for(int j = n; j >= i; j--){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
triangleLU(5);
}
}
3. 오른쪽 위가 직각인 이등변삼각형 만들기
*****
****
***
**
*
package chap01;
public class practice14_3 {
//오른쪽 위가 직각인 이등변삼각형
static void triangleLU(int n){
for (int i = 1; i <= n; i++){
for(int j = 1; j <= i - 1; j++){
System.out.print(" ");
}
for(int j = n; j >= i; j--){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
triangleLU(5);
}
}
4. 오른쪽 아래가 직각인 이등변삼각형 만들기
*
**
***
****
*****
package chap01;
public class practice14_4 {
//오른쪽 아래가 직각인 이등변삼각형
static void triangleLU(int n){
for (int i = 1; i <= n; i++){
for(int j = n; j >= i; j--){
System.out.print(" ");
}
for(int j = 1; j <= i; j++){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
triangleLU(5);
}
}
5. n단의 피라미드 만들기
*
***
*****
*******
*********
package chap01;
public class practice15 {
//n단의 피라미드를 출력하는 메서드를 작성하세요.
static void triangleLU(int n){
for (int i = 1; i <= n; i++){
for(int j = 1; j <= n - i; j++){
System.out.print(" ");
}
for(int j = 1; j <= (i-1)*2+1; j++){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
triangleLU(5);
}
}
6. n단의 숫자 피라미드 만들기
1
333
55555
7777777
999999999
package chap01;
public class practice16 {
//아래를 향한 n단의 숫자 피라미드를 출력하는 메서드를 작성하세요.
static void triangleLU(int n){
for (int i = 1; i <= n; i++){
for(int j = 1; j <= n - i; j++){
System.out.print(" ");
}
for(int j = 1; j <= (i-1)*2+1; j++){
System.out.print((i-1)*2+1);
}
System.out.println();
}
}
public static void main(String[] args) {
triangleLU(5);
}
}
728x90
320x100
'💻 하나씩 차곡차곡 > 자료구조 & 알고리즘(JAVA)' 카테고리의 다른 글
배열요소를 역순으로 정리하기 (chap02/ReverseArray) (0) | 2022.10.17 |
---|---|
배열요소의 최댓값 구하기 (chap02/MaxOfArray) (0) | 2022.10.16 |
이중루프를 사용하여 구구단 곱셈표 출력하기 (chap01/Multi99Table) (1) | 2022.10.13 |
2자리 양수만 입력받기 (chap01/Twodigits) (0) | 2022.10.12 |
*를 n개 출력하되 w개마다 줄 바꿈하기 (chap01/PrintStras1,2) (0) | 2022.10.11 |