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 }}
root-devvoo
Java-Data_Structure
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Java-Data_Structure
/
Chapter1
/
src
/
Section2
/
Code19.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
36 lines (32 loc) · 1.56 KB
main
Breadcrumbs
Java-Data_Structure
/
Chapter1
/
src
/
Section2
/
Code19.java
Copy path
Top
File metadata and controls
Code
Blame
36 lines (32 loc) · 1.56 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
package
Section2
;
import
java
.
io
.
File
;
import
java
.
io
.
FileNotFoundException
;
import
java
.
util
.
Scanner
;
/* input.txt라는 파일로부터 사람들의 이름과 전화번호 쌍을 입력받아
* 배열에 저장하고 출력한다.
*/
public
class
Code19
{
public
static
void
main
(
String
[]
args
) {
String
[]
name
=
new
String
[
1000
];
// 배열의 크기 1000으로 지정
String
[]
number
=
new
String
[
1000
];
int
n
=
0
;
// n은 사람 수
// FileNotFoundException 처리를 위해 try, catch문으로 감쌈
try
{
Scanner
sc
=
new
Scanner
(
new
File
(
"input.txt"
));
// 데이터 파일은 프로젝트 폴더에 있어야 한다.
// System.in 대신에 데이터 파일의 이름을 지정하고 File을 만든 후 그 파일에 대한 Scanner를 만든다.
while
(
sc
.
hasNext
()) {
// 스캐너.hasNext() 메서드는 파일의 끝에 도달했는지 검사한다. 파일 안에서 더 읽을거리가 없으면 false를 리턴
// detect End of File
name
[
n
] =
sc
.
next
();
// 스캐너.next() 메서드는 하나의 문자열을 입력해줌
number
[
n
] =
sc
.
next
();
n
++;
}
sc
.
close
();
}
catch
(
FileNotFoundException
e
) {
System
.
out
.
println
(
"No file"
);
System
.
exit
(
9
);
// 프로그램 자체를 실행할 수 없으므로 종료시키는 메서드 System.exit()
// status 0은 정상적인 종료를 의미, 0이 아닌 값은 프로그램의 비정상적인 오류로 종료됐음을 의미
}
for
(
int
i
=
0
;
i
<
n
;
i
++)
System
.
out
.
println
(
name
[
i
] +
": "
+
number
[
i
]);
}
}
You can’t perform that action at this time.