Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 0x02/이현희/X보다_작은_수.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();
int x = sc.nextInt();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 저랑 똑같이 하셨네요!!!
저는 스캐너 대신 BufferedReader랑 StringTokenizer를 사용하였는데,
입출력시 속도 차이가 있어서, 나중엔 같은 구문이더라도, 스캐너를 사용하면
런타임 에러가 뜨는 경우가 있더라구요!!
이부분도 한 번 확인해보시면 좋을 것 같습니다!!


for (int i = 0; i < n; i++) {
int inputData = sc.nextInt();
if (inputData < x) {
System.out.print(inputData + " ");
}
}
}
}
42 changes: 42 additions & 0 deletions 0x02/이현희/별_찍기_-_7.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

// 위
for (int i = 1; i < n; i++) {
// 빈칸
for (int j = 0; j < n - i; j++) {
System.out.print(" ");
}
// 별
for (int j = 0; j < 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}

// 가운데
for (int i = 0; i < 2 * n - 1; i++) {
System.out.print("*");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전 가운데까지 포함해서 위~ / 아래 이렇게 구현했었는데,
현희님 방식처럼 위 - 가운데 - 아래 도 깔끔하게 보기 좋네요!!

System.out.println();

// 아래
for (int i = n - 1; i > 0; i--) {
// 빈칸
for (int j = 0; j < n - i; j++) {
System.out.print(" ");
}
// 별
for (int j = 0; j < 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
41 changes: 41 additions & 0 deletions 0x02/이현희/별_찍기_-_8.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
for (int j = 0; j < 2 * (n - i); j++) {
System.out.print(" ");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전 이부분 구현을 똑바로 못했어서
왼쪽공백 / 오른쪽 공백 느낌으로 반복문을 두 번 사용하였는데,
이렇게 구현하면 한번에 가능하네요!! 배워갑니다.

for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}

for (int i = 0; i < 2 * n; i++) {
System.out.print("*");
}
System.out.println();

for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
for (int j = 0; j < 2 * (n - i); j++) {
System.out.print(" ");
}
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
36 changes: 36 additions & 0 deletions 0x02/이현희/별_찍기_-_9.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < n - i - 1; j++) {
System.out.print(" ");
}

for (int j = 0; j < 2 * i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 윗 삼각형 부분을 이런식으로 구현했습니다.

for (int i = 0; i <n; i++) { // 윗 삼각형
for (int j = 0; j < i; j++) { // 공백
sb.append(" ");
}
for (int j = 1; j <= 2*(n-i)-1; j++) { // 별
sb.append("*");
}
sb.append("\n"); // 줄 바꿈
}

큰 반복문 부분에서 저는 i값이 0부터 증가하는 것으로 구현하였는데,
현희님은 반대로 n-1부터 감소하는 느낌으로 구현하셨네요!
한 번 비교해보셔도 좋을 것 같아서 올려봅니다!


for (int i = 0; i < n - 1; i++) {
System.out.print(" ");
}
System.out.println("*");

for (int i = 1; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
20 changes: 20 additions & 0 deletions 0x02/이현희/최댓값.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.*;

public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

List<Integer> arr = new ArrayList<>();

for (int i = 0; i < 9; i++) {
arr.add(Integer.valueOf(sc.nextInt()));
}

int max = Collections.max(arr);
int index = arr.indexOf(max);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 Collections를 응용해서 해결하고 싶었는데, 자꾸 오류가 나서 실패했었어요
Collections.sort만 생각했는데, max를 활용하는 건 생각 못했네요
배워갑니다.


System.out.println(max);
System.out.println(index + 1);
}
}