Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1주차 Assignment - 이승현 #9

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
92 changes: 92 additions & 0 deletions LEE SEUNG HYUN/assigns/Test1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package assigns;

// 다음 조건을 만족하도록 Cylinder 클래스를 작성합니다.
class Cylinder {

public static final double PI = 3.14;// 원주율 3.14를 정적 상수 PI로 선언과 동시에 초기화

int x, y;// 정수형 원의 중심 좌표 x, y를 선언

Choose a reason for hiding this comment

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

클래스의 필드를 아래와 같이 private으로 선언하는 것이 객체 지향 프로그래밍의 중요한 원칙 중 하나인 캡슐화를 구현하기 위한 좋은 방법입니다. 참고해주세요!

private int x, y;
private double r;
private int height = 10;


double r;// 실수형 원의 반지름 r을 선언

int height = 10;// 정수형 원기둥의 높이 height를 10으로 선언과 동시에 초기화


public Cylinder(int x, int y, double r) {
this(x, y, 10, r); // 생성자2 호출
}

// 생성자1: 정수 인자 x, y 와 실수 인자 r을 전달 받아서 해당 필드 값을 초기화

public Cylinder(int x, int y, int height, double r) {
this.x = x;
this.y = y;
this.height = height;
this.r = r;
}// 생성자2: 정수 인자 x, y, height 와 실수 인자 r을 전달 받아서 해당 필드 값을 초기화


public double circleArea() {
return PI * r * r;
}// circleArea 메서드: PI를 이용하여 원의 면적 반환


public double volume() {
return circleArea() * height;
}// volume 메서드: 면적과 높이를 이용하여 부피를 반환


public double surfaceArea() {
return (2 * circleArea()) + (2 * PI * height * r);
}// surfaceArea 메서드: PI를 이용하여 원기둥의 겉넓이를 반환


public void move(int dx, int dy) {
this.x += dx;
this.y += dy;

}

// move 메서드: 정수 인자 dx, dy를 전달 받아서 원의 중심 좌표를 이동
// - 예: 필드 x가 1이고 dx가 10이면 x는 11로 변경되어야 함
// 객체 자신을 반환
public void print() {
System.out.println("<" + x + "," + y + ":" + r + ">");
}
}


// 메인메서드 수행시 이렇게 출력되도록
//<13,15:6.0>
//113.04
//1130.4
//602.88
//<17,25:10.0>
//314.0
//1570.0
//942.0


public class Test1 {
public static void main(String[] args) {
// 객체 생성
Cylinder c1 = new Cylinder(3, 5, 6);
c1.move(10, 10);

// 정보 출력
c1.print();
System.out.printf("%.2f\n", c1.circleArea());
System.out.printf("%.1f\n", c1.volume());
System.out.printf("%.2f\n", c1.surfaceArea());

// 객체 생성

Choose a reason for hiding this comment

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

실행 시 다른 결과가 나옵니다! 수정부탁드려요!

Cylinder c2 = new Cylinder(5, 8, 10, 5);
c2.move(12, 17);

// 정보 출력
c2.print();
System.out.printf("%.1f\n", c2.circleArea());
System.out.printf("%.1f\n", c2.volume());
System.out.printf("%.1f\n", c2.surfaceArea());
}
}
30 changes: 30 additions & 0 deletions LEE SEUNG HYUN/bj_10810/bj_10810/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package bj_10810.bj_10810;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

Choose a reason for hiding this comment

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

Scanner 잘 사용해주신 거같은데 이 Scanner가 사용하기 쉽지만 대량의 데이터를 입력 받을 때 성능 문제가 생길 수 있습니다. 더 효율적인 코드를 위해서는 BufferedReader를 사용하는 것도 추천드립니다. 아래 블로그 참고해보시면 좋을 거같습니다~!

https://rlakuku-program.tistory.com/33


int M = scanner.nextInt();
int N = scanner.nextInt();

int n1, n2, ball = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

한 줄에 다중 변수를 선언해도 문제는 없지만 추천하지는 않습니다!

Copy link
Author

Choose a reason for hiding this comment

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

넵 넵 수정 하겠습니다.


int array1[] = new int[M];

for(int i=0;i<N;i = i + 1) {

Choose a reason for hiding this comment

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

for 중첩 반복문 잘 활용하셨는데 앞으로 가독성을 위해 for(int i=0;i<N;i = i + 1) 보다는 for (int i = 0; i < N; i = i + 1) 이렇게 작성해주시는 걸 추천드립니다!

n1 = scanner.nextInt()-1;
n2 = scanner.nextInt()-1;
ball = scanner.nextInt();

for(int j=n1;j<=n2;j = j + 1) {
array1[j] = ball;
}
}

for(int i=0;i<array1.length;i = i + 1) {
System.out.print(array1[i]+" ");
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions LEE SEUNG HYUN/bj_11021/bj_11021/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package bj_11021.bj_11021;

import java.util.Scanner;
public class Main {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int T = scanner.nextInt();
int i = 1;

while (i <= T) {

Choose a reason for hiding this comment

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

여기서 반복문 잘 사용하셨네요. T의 값을 입력받고 i를 선언 및 초기화를 해준다음 while문 안에서 i가 계속해서 증가하도록 잘 작성해주셨습니다.

int A = scanner.nextInt();
int B = scanner.nextInt();


System.out.println("Case #" + i + ": " + (A + B));
i = i + 1;

}

}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions LEE SEUNG HYUN/bj_2439/bj_2439/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package bj_2439.bj_2439;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int N = scanner.nextInt();

Choose a reason for hiding this comment

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

백준에서는 N으로 변수를 지정하라 했을 수도 있긴 한데 앞으로 변수는 소문자로 작성하고 명시적인 것으로 네이밍하면 좋을 거같아요.


int i = 1;

while (i <= N){
int J = 1;

while (J <= N - i) {
System.out.print(" ");
J = J + 1;
}

J = 1;
while (J <= i) {
System.out.print("*");
J = J + 1;
}

System.out.println();

i = i + 1;
}
}
}






Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions LEE SEUNG HYUN/bj_2588/bj_2588/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package bj_2588.bj_2588;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// 두 개의 정수 입력
int a = scanner.nextInt();
int b = scanner.nextInt();

// 각 자릿수에 대한 곱 계산
int result1 = a * (b % 10);
int result2 = a * ((b % 100) / 10);
int result3 = a * (b / 100);

// 전체 곱 계산
int totalResult = a * b;

// 결과 출력
System.out.println(result1);
System.out.println(result2);
System.out.println(result3);
System.out.println(totalResult);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions LEE SEUNG HYUN/bj_2884/bj_2884/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package bj_2884.bj_2884;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);


int H = scanner.nextInt();
int M = scanner.nextInt();

if (M < 45){
H = H - 1;
M = 60 - (45 - M);

if (H < 0) {
H = 23;
}
System.out.println(H + " " + M);
}

else{
System.out.println(H + " " + (M-45));
}

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions LEE SEUNG HYUN/bj_9086/bj_9086/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package bj_9086.bj_9086;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int T = scanner.nextInt();
scanner.nextLine();

for (int i = 0; i < T; i = i + 1 ){
String str = scanner.nextLine(); // 문자열로 입력받기

char[] charArray = str.toCharArray(); //입력받은 문자열을 문자형으로 변환
char first = charArray[0];
char last = charArray[str.length() - 1]; //인덱스는 0 부터 시작

System.out.println( first + "" + last);
}

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.