Nothing is impossible
随便写了一个垃圾的, 你参考看考
import java.math.BigDecimal;
class DrinkedWalker {
static void walk(int[][] road) {
int x = 0, y = 0;
for (int i = 0; i < 1000; i++) {
double randomNum = Math.random();
BigDecimal b = new BigDecimal(randomNum);
float roundNum = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
String strDirect = Long.toString(Math.round(roundNum / 0.25));
int direction = Integer.parseInt(strDirect);
int tmpX = x, tmpY = y;
switch(direction) {
case 0:
case 1:
x = x - 1;
break;
case 2:
y = y + 1;
break;
case 3:
x = x + 1;
break;
default:
y = y - 1;
}
if (x >= 0 && y >= 0 && road[x][y] != 1) {
road[x][y] = 1;
} else {
System.out.println("Stop at x=" + tmpX + "; y=" + tmpY);
return;
}
}
System.out.println("Stop at x=" + x + "; y=" + y);
return;
}
public static void main(String[] args) {
int[][] road = new int[100][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
road[i][j] = 0;
}
}
walk(road);
}
}
随便写了一个垃圾的, 你参考看考
import java.math.BigDecimal;
class DrinkedWalker {
static void walk(int[][] road) {
int x = 0, y = 0;
for (int i = 0; i < 1000; i++) {
double randomNum = Math.random();
BigDecimal b = new BigDecimal(randomNum);
float roundNum = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
String strDirect = Long.toString(Math.round(roundNum / 0.25));
int direction = Integer.parseInt(strDirect);
int tmpX = x, tmpY = y;
switch(direction) {
case 0:
case 1:
x = x - 1;
break;
case 2:
y = y + 1;
break;
case 3:
x = x + 1;
break;
default:
y = y - 1;
}
if (x >= 0 && y >= 0 && road[x][y] != 1) {
road[x][y] = 1;
} else {
System.out.println("Stop at x=" + tmpX + "; y=" + tmpY);
return;
}
}
System.out.println("Stop at x=" + x + "; y=" + y);
return;
}
public static void main(String[] args) {
int[][] road = new int[100][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
road[i][j] = 0;
}
}
walk(road);
}
}
请问高手用那种语言编的?Java?大概能看懂,只是有些命令语句没见过。