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
Events
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
/
week02
/
intermediate
/
ProductTest.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
30 lines (23 loc) · 1.13 KB
main
Breadcrumbs
java-practice
/
week02
/
intermediate
/
ProductTest.java
Copy path
Top
File metadata and controls
Code
Blame
30 lines (23 loc) · 1.13 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
package week02.intermediate;
public class ProductTest {
public static void main(String[] args) {
System.out.println("<특정 조건의 객체만 골라내기>");
// 15단계(응용): 특정 조건의 객체만 골라내기
// 문제: Product.java에 상품명(name)과 가격(price) 멤버 변수를 만드세요.ProductTest.java에서
// Product 객체 배열에 여러 상품 정보를 저장하세요. for문과 if문을 사용하여 가격이 10000원 이상인 상품의
// 이름만 출력하세요.
// 핵심 사고: 객체 배열을 순회하며 각 객체의 상태(멤버 변수)에 따라 조건부 로직을 처리하는 능력을 기릅니다.
// 힌트: 객체 배열, 클래스, for문, if문, getter, 비교 연산자
Product [] product = new Product[5];
product[0] = new Product ("사과",12000);
product[1] = new Product ("두부",1500);
product[2] = new Product ("계란",11000);
product[3] = new Product ("우유",2000);
product[4] = new Product ("닭",15000);
for( Product p : product ) {
if(p.getPrice()>=10000) {
System.out.println(p.getName());
}
}
}
}
You can’t perform that action at this time.