gpt4 book ai didi

java - 说明 数组列表

转载 作者:行者123 更新时间:2023-12-01 17:32:52 29 4
gpt4 key购买 nike

如何创建值有序对的列表,例如list1 [(x, y), (x1, y1) ...].??

学习如何创建此列表后,我需要知道如何将 x 值提供给列表中的用户输入并搜索 x 的下一个值并显示有序对 (x, y)?

最佳答案

您可能想要创建 Point 的列表。首先定义Point类,

public class Point
{
private int x,y;
public int getX() { return x;}
public int getY() { return y;}
public void setX(int x) { this.x=x;}
public void setY(int y) { this.y=y;}

public Point() {}
public Point(int x,int y) { this.x=x; this.y=y;}
}

并创建List<Point>.

List<Point> points=new ArrayList<Point>();

添加点对象引用,

points.add(new Point(3,3));
points.add(new Point(4,5));

返回点对象引用,

System.out.println(points.get(0).getX());

关于java - 说明 数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9329037/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com