Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
hyebin-dev
java-practice
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
java-practice
/
week03
/
basic
/
TryCatchFinallyParseInts.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
37 lines (32 loc) · 1.35 KB
main
Breadcrumbs
java-practice
/
week03
/
basic
/
TryCatchFinallyParseInts.java
Copy path
Top
File metadata and controls
Code
Blame
37 lines (32 loc) · 1.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
33
34
35
36
37
package week03.basic;
import java.util.ArrayList;
import java.util.List;
public class TryCatchFinallyParseInts {
public static void main(String[] args) {
System.out.println("<예외 기본: try/catch/finally 동작 확인>");
// B-7) 예외 기본: try/catch/finally 동작 확인
// 문제: 문자열 배열에서 정수만 파싱해 리스트로 모으되, 숫자가 아니면 `NumberFormatException`을 잡아
// 건너뛰고, 마지막에 `finally`에서 `"done"`을 출력하라.
// 문제설명: `try` 블록에서 예외가 나면 곧바로 해당 타입의 `catch`로 흐름이 이동한다.
// `finally`는 예외 발생과 관계없이 항상 실행된다. 이 패턴은 입력 정제에 자주 쓰인다.
// 힌트: `try { ... } catch (NumberFormatException e) { ... } finally { ... }`,
// `ArrayList`.
String [] str = {"8", "e", "com", "321", "no", "9", "k", "3", "hi", "93"};
List<Integer>list = new ArrayList<>();
try {
for (int i =0; i < str.length; i++) {
String trimStr = str[i].trim(); // 공백제거
if (trimStr.isEmpty()) { // 비어있는 칸 조기종료
continue;
}
try {
list.add(Integer.parseInt(trimStr));// 정수이면 list에 추가
} catch (NumberFormatException e) {
}
}
} finally {
System.out.println("done");
}
System.out.println(list);
}
}
You can’t perform that action at this time.