do{
int k=random.nextInt(1000);
}while(k==0);
你的k是定义在do语句中的,所以不能在while中使用
int k; //k应该为全局变量
k=random.nextInt(1000);