일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 자바
- 오류모음
- 공부
- 파워서플라이
- 순환문
- 백준문제
- 전화번호부
- jsp
- while
- 이클립스
- Oracle
- ORA-01407
- for문
- 이클립스단축기
- 오류
- Ajax
- ORA-02292
- 설정
- 백준
- spring
- 스프링
- 깃허브 블로그
- 환경설정
- 백준문제풀이
- 오라클
- 별 찍기
- MSI
- 인터페이스
- 티스토리 블로그
- 무결성 제약조건
Archives
- Today
- Total
danDevlog
Java - day4 본문
728x90
// 피라미드 별 출력
// 1, 3, 5, 7, 9... 씩 늘어나는 규칙을 알아내는 것이 중요
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for(int i = 0; i<a; i++) {
for(int j = 0; j<=a-i; j++) {
System.out.print(" ");
}
for(int k = 0; k<i*2+1; k++) {
System.out.print("*");
}
System.out.println();
}
sc.close();
}
}
// 다이아몬드 모양 출력
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for(int i = 0; i<a; i++) {
for(int j = 1; j<a-i; j++) {
System.out.print(" ");
}
for(int k = 0; k<i*2+1; k++) {
System.out.print("*");
}
System.out.println();
}
for(int i = a-1; i>0; i--) {
for(int j=a-i; j>0; j--) {
System.out.print(" ");
}
for(int j=i*2-1; j>0; j--) {
System.out.print("*");
}
System.out.println();
}
sc.close();
}
}
// 역 다이아몬드 출력
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
// 맨 윗줄
for(int i=1; i<=a; i++) {
System.out.print("+");
}
System.out.println();
// 상반부
for(int i=1; i<=a/2; i++){
for(int j=0; j<a/2-i+1; j++) System.out.print("+");
for(int j=0; j<i*2-1; j++) System.out.print(" ");
for(int j=0; j<a/2-i+1; j++) System.out.print("+");
System.out.println();
}
// 하부
for(int i=1; i<=a/2; i++){
for(int j=0; j<i; j++) System.out.print("+");
for(int j=0; j<a-2*i; j++) System.out.print(" ");
for(int j=0; j<i; j++) System.out.print("+");
System.out.println();
}
// 맨 아랫줄
for(int i=1; i<=a; i++) {
System.out.print("+");
}
sc.close();
}
}
// 모래시계 별 찍기
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for(int i=a; i>=1; i--) {
for(int j=1; j<=a-i; j++) {
System.out.print(" ");
}
for(int k=1; k<=i*2-1; k++) {
System.out.print("*");
}
System.out.println();
}
for(int i=2; i<=a; i++) {
for(int j=1; j<=a-i; j++) {
System.out.print(" ");
}
for(int k=1; k<=i*2-1; k++) {
System.out.print("*");
}
System.out.println();
}
sc.close();
}
}
// 구구단 단별 출력 예제1
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
int startDan = 2; // 시작 단
int endDan = 9; // 끝 단
int danPerLine = 3; // 한 줄에 출력할 단수.
int maxGudan = 9; // 계산할 구단수
for (int dadan = startDan; dadan <= endDan; dadan += danPerLine) {
// dadan: 맨 왼쪽 단
for (int gudan = 1; gudan <= maxGudan; gudan++) {
int currentDanMax = dadan + (danPerLine - 1); // 현재 줄에서 가장 오른쪽에 놓일 단
for (int danline = dadan;
danline <= ((currentDanMax <= endDan) ? currentDanMax : endDan);
danline++) {
// 왼쪽 단부터 오른쪽 단까지 한 단씩 출력.
// 단 오른쪽 단이 계산할 구단수보다 많으면 그 단 출력 안 함.
System.out.print(danline + " x " + gudan + " = " + (danline * gudan) + "\t");
}
// 다음 줄로 넘기기
System.out.println();
}
// 지난 문단의 단들과 간격 만들기
System.out.println();
}
}
}
// 입력 없이 9단까지
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
int i,j,k;
for(k=2; k<=9; k=k+3) {
for(i=1; i<=9;i++) {
for(j=k; j<k+3 && j<10; j++) {
System.out.printf("%d*%d=" + j*i + "\t", j,i);
}
System.out.println("");
}
System.out.println("");
System.out.println("");
}
}
}
'Java' 카테고리의 다른 글
Java - day6 (0) | 2022.02.22 |
---|---|
Java - day5 (0) | 2022.02.21 |
Java - day3 (0) | 2022.02.17 |
Java - day2 (0) | 2022.02.16 |
Java - day1 (0) | 2022.02.15 |
Comments