📄 randomcity.java
字号:
/*
*
*
* this file is to generate a map of cities with random
* locations within a square area (BORDER*BORDER)
*
* usage: java RandomCity <number of cities> <output file>
*
* Author: Liu Yang
*
* 20/04/2006
* */
import java.util.Random;
public class RandomCity{ private static int numOfCities = 0; public static void main(String[] args)
{
if (args.length != 2){
System.out.println("Usage: ");
System.out.println("java RandomCity <number of cities> <output file>");
return;
} try {
numOfCities = Integer.parseInt(args[0]);
if(numOfCities < 0)
throw new NumberFormatException();
}
catch(NumberFormatException e){
System.out.println("Invalid number of cities: "+args[0]);
throw e;
}
CityMap citymap = new CityMap();
Random m_random = new Random();
int BODER = 10;
for(int i=0; i<numOfCities; i++){
citymap.addCity( m_random.nextDouble() * BODER,m_random.nextDouble() * BODER );
}
try{
citymap.save(args[1]);
}catch (Exception e){
System.out.println(e);
}
}//end main
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -