-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
미해결
문법질문입니다.
23.02.07 21:03 작성 조회수 269
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