Java 请帮助一下啦?下面的程序错在哪?在do那行它提示非法的类型开始

来源:百度知道 编辑:UC知道 时间:2024/05/05 16:04:10
import java.util.Random;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author stud
*/
public class Java_2 {

Random random = new Random();
float x = random.nextFloat();//产生0.0与1.0之间的一个符点数
int n = Math.round(20*x); //构造20以内的一个整数
long f = 1 ; //保存阶乘的结果
int k = 1 ; //循环变量
//*********Found********
do{
f*=k;
k++;
//*********Found********
}while (k<=n)
System.out.println(n+"!= "+f);
}

1、程序没有main()主函数。
2、在while (k<=n) 后应加分号;。

修改后程序:
import java.util.Random;
public class Java_2{

public static void main(String[] args) {
Random random = new Random();
float x = random.nextFloat();//产生0.0与1.0之间的一个符点数
int n = Math.round(20*x); //构造20以内的一个整数
long f = 1 ; //保存阶乘的结果
int k = 1 ; //循环变量

do{
f*=k;
k++;
}while (k<=n);
}
}

while (k<=n) 后面少了一个分号