문법질문입니다.
418
리쿤
작성한 질문수 8
0
import java.nio.channels.Pipe;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class Point implements Comparable<Point>{
public int x, y;
Point(int x, int y){
this.x = x;
this.y = y;
}
@Override
public int compareTo(Point o){
if(this.x == o.x) return this.y-o.y;
else return this.x-o.x;
}
}
class Main{
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
ArrayList<Point> arr = new ArrayList<>();
for(int i = 0; i < n; i++){
int x= kb.nextInt();
int y= kb.nextInt();
System.out.println(x+","+y);
arr.add(new Point(x, y));
}
Collections.sort(arr);
System.out.println(">>");
for (Point o: arr) System.out.println(o.x+" "+o.y);
}
}
arr.add(new Point(x, y));이 부분을 출력해서 값을 프린트하고 싶은데 어떻게 코드를 짜야하나요??
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
ArrayList<Point> arr = new ArrayList<>();
for(int i = 0; i < n; i++){
int res;
int x= kb.nextInt();
int y= kb.nextInt();
System.out.println(x+","+y);
arr.add(new Point(x, y));
res = arr.add(new Point(x, y));
System.out.println(res);
}이렇게 res 변수를 만들어서 작석했는데 에러가 나네요 ㅠ 도와주세요ㅠㅠㅠ
답변 1
안녕하세요. 바뀐 채점사이트 관련해서 문의드립니다.
0
16
1
갑자기 채점 사이트가 바뀌었어요
0
19
1
문제 리스트 페이지
0
22
1
채점 사이트 관련 질문드립니다
0
20
1
봉우리 문제 질문입니다
0
78
2
씨름 선수 문제에서 각 선수의 몸무게나 키가 같을 수도 있다면?
0
62
0
이 코드랑 영상 코드중에 뭐가 더 좋은 코드인가요?
0
70
0
가중치 방향 그래프에서 가중치가 0인 간선을 표현하는 방법
0
67
1
좌표 정렬 문제 이 코드가 왜 틀린지 모르겠습니다 ㅠㅠ
0
82
2
6-7 강의에서
0
47
1
6-6. 장난꾸러기 질문 있습니다.
0
43
1
강의 수강후 코딩테스트
0
106
1
answer 변수 사용 여부
0
42
1
2중 for문
1
83
2
2-11. 임시반장정하기 (Runtime Error)
0
62
1
혹시 LinkedList 같은 자료 구조들은 따로 배우지 않나요?
0
68
1
이런 풀이는 어떨까요
0
42
1
자바 스트림 방식의 효율성 질문 드립니다.
0
55
1
알고리즘 자료 구조들..
0
59
1
StringBuilder vs BufferdWriter
0
46
1
원더랜드(프림)
0
47
1
이런 코드는 어떤가요?
0
59
1
bfs 풀이
0
55
1
병합정렬
0
54
1





