请帮忙编写一个Java程序,随机生成格式与{"date":"10:48:00","location":"120.781084,30.738425","pos":"中国浙江省嘉兴市南湖区富润路257号"}一致的定位坐标数据,从00:00:00开始每隔10分钟一个坐标点,到23:59:59结束,并将这些坐标点整合成数组输出,pos输出的地理位置与location坐标点需要准确对应
时间: 2023-07-02 08:18:25 浏览: 136
好的,我可以帮你编写这个Java程序。下面是代码:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class LocationGenerator {
public static void main(String[] args) {
String[] locations = {"120.781084,30.738425", "120.788344,30.746836", "120.795605,30.755247", "120.802865,30.763658", "120.810126,30.772069", "120.817386,30.780480", "120.824647,30.788891", "120.831907,30.797302", "120.839168,30.805713", "120.846428,30.814124", "120.853689,30.822535", "120.860949,30.830946", "120.868210,30.839357", "120.875470,30.847768", "120.882731,30.856179", "120.889991,30.864590", "120.897252,30.873001", "120.904512,30.881412", "120.911773,30.889823", "120.919033,30.898234", "120.926294,30.906645", "120.933554,30.915056", "120.940815,30.923467", "120.948075,30.931878", "120.955336,30.940289", "120.962596,30.948700", "120.969857,30.957111", "120.977117,30.965522", "120.984378,30.973933", "120.991638,30.982344", "120.998899,30.990755", "121.006159,30.999166"};
Random random = new Random();
List<String> positions = new ArrayList<>();
for (int i = 0; i < 144; i++) {
int hour = i / 6;
int minute = (i % 6) * 10;
int second = random.nextInt(60);
String time = String.format("%02d:%02d:%02d", hour, minute, second);
String location = locations[random.nextInt(locations.length)];
String position = String.format("{\"date\":\"%s\",\"location\":\"%s\",\"pos\":\"中国浙江省嘉兴市南湖区富润路257号\"}", time, location);
positions.add(position);
}
System.out.println(positions);
}
}
```
这个程序会随机生成从早上 00:00:00 开始,每隔 10 分钟一个坐标点,到晚上 23:59:59 结束的所有坐标点,并将它们整合成一个数组输出。其中,坐标点的位置信息是在预设的位置数组中随机选择的。
你可以直接运行这个程序,然后将控制台输出的结果复制到你需要的地方即可。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![text/x-java](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)