小编Djc*_*123的帖子

存储X和Y坐标

您好我是这个网站的新手,需要帮助我正在努力的程序.我遇到的问题是我似乎无法存储字符串和两个整数(作为坐标).我查看了其他代码,但没有看到值的存储方式.下面是我一直在使用的代码.代码似乎没问题,但在尝试存储值时,我不能将乘法整数.谢谢你的时间

import java.util.HashMap;
public class map {

    class Coords {
        int x;
        int y;

        public boolean equals(Object o) {
            Coords c = (Coords) o;
            return c.x == x && c.y == y;
        }

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

        public int hashCode() {
            return new Integer(x + "0" + y);
        }
    }

    public static void main(String args[]) {

        HashMap<Coords, Character> map = new HashMap<Coords, Character>();
        map.put(new coords(65, 72), "Dan");
    }

}
Run Code Online (Sandbox Code Playgroud)

java coordinates

5
推荐指数
2
解决办法
6万
查看次数

从用户坐标中找到最近的点

我想知道如何使用坐标找到关闭点.我正在使用一个包含坐标和字符串的Hashmap.我允许用户输入x和y轴并将它们存储为int a和int b但我不知道从那里去哪里.谢谢你的期待

import java.util.HashMap;
import java.util.Scanner;

public class Coordinate {

static class Coords {
    int x;
    int y;

    public boolean equals(Object o) {
        Coords c = (Coords) o;
        return c.x == x && c.y == y;
    }

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

    public int hashCode() {
        return new Integer(x + "0" + y);
    }

    public String toString()
    {
        return x + ";" + y;
    }


}

public static void main(String …
Run Code Online (Sandbox Code Playgroud)

java user-input hashmap coordinates

3
推荐指数
1
解决办法
9002
查看次数

标签 统计

coordinates ×2

java ×2

hashmap ×1

user-input ×1