这种错误怎么改呀
下面是代码
public interface ComputeWeight{
double ComputeWeight();
}
public class ComputeWeight implements Television
{
double w1;
Television(double w1)
{
super();
this.w1 = w1;
}
return double w1;
}
public class ComputeWeight implements AirConditioner
{
double w2;
AirConditioner(double w2)
{
super();
this.w2 = w2;
}
return w2;
}
public class ComputeWeight implements WashMachine
{
double w3;
WashMachine(double w3)
{
super();
this.w3 = w3;
}
return w3;
}
public class Truck {
private ComputeWeight goods[];
Truck(ComputerWeight[] goods)
{
super();
this.goods = goods;
}
public double getTotalWeight()
{
double sum = 0;
for (i = 0;i<goods.length ;i++)
{
type=input.nextInt();
if (type==1)
sum = sum +16.6;
else if (type==2)
sum = sum + 40.0;
else if (type==3)
sum = sum +60.0;
}
return sum;
}
}
构造方法 要和 当前类 同名, 你都是 和 父类或接口同名 ,这是错误的
在java.util这个包里面提供了一个Random的类,我们可以新建一个Random的对象来产生随机数,他可以产生随机整数、随机float、随机double,随机long。Random的对象有两种构建方式:带种子和不带种子。不带种子的方式将会返回随机的数字,每次运行结果不一样。无论程序运行多少次,带种子方式构建的Random对象会返回一样的结果。
请编写程序,使用第一种方式构建Random对象,并完成下面输入输出要求。
输入格式:
在一行中输入3个不超过10000的正整数n,m,k。
输出格式:
在一行中输出以k为种子建立的Random对象产生的第n个0到m-1之间的伪随机数。
输入样例:
10 100 1000
输出样例:
50
答案:
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
List<Integer> ss = new ArrayList<Integer>();
//Set<Integer> ss = new HashSet<Integer>();
Random rand = new Random(k);
for(int i = 0;i < n;i++)
{
ss.add(rand.nextInt(m));
if(i==n-1)
System.out.println(ss.get(i));
}
}
}