-
Notifications
You must be signed in to change notification settings - Fork 85
[전서영] 계산기 구현 1차 #60
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
base: main
Are you sure you want to change the base?
[전서영] 계산기 구현 1차 #60
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.util.Scanner; | ||
public class Calculator { | ||
public static void main(String[] args) { | ||
//여기서부터 프로그램 시작 | ||
System.out.println("[전서영] 1주차 계산기 구현 과제"); | ||
// Scanner 객체 생성 | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
// 숫자 입력받기 | ||
System.out.println("Please enter the numbers. : "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 숫자만 입력받는 형식이 아니기 때문에, |
||
String expression = scanner.nextLine(); | ||
|
||
// 쉼표와 콜론으로 숫자들 분리 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 계산 로직을 별개의 메소드로 분리하면 좋을 것 같아요! |
||
String[] tokens = expression.split("[,|:]"); | ||
|
||
int sum = 0; | ||
for (String token : tokens) { | ||
sum += Integer.parseInt(token); | ||
} | ||
|
||
System.out.println("Results: " + sum); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 유효하지 않은 값이나, 음수 값이 입력되었을 경우 등에 대한 예외 처리가 필요할 것 같아요! |
||
scanner.close(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요구사항에 메인 메소드를 사용하지 말라는 부분이 있었습니다!