Java/SWEA
[JAVA] SWEA 16910. 원 안의 점
쥬크버그
2024. 5. 11. 17:23
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
정답
- 음수인 점도 고려해야 하므로 for 문의 범위를 -n부터 n까지 설정
import java.util.Scanner;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T =sc.nextInt();
for(int tc = 1; tc <= T; tc++)
{
int N = sc.nextInt(); //반지름
int answer =0;
for(int i=-N; i<N+1; i++)
{
for(int j=-N; j<N+1; j++)
{
if(Math.pow(i,2)+Math.pow(j,2)<=Math.pow(N,2))
{
answer++;
}
}
}
System.out.printf("#%d %d\n",tc,answer);
}
}
}