package com.Project;public class Shouji { float screen; float cpu; float cem; public Shouji(){ System.out.println("无参的构造方法执行啦!"); } public Shouji(float newScreen,float newCpu,float newCem){ if(screen<3.5f){ System.out.println("你输入的参数有误,制动赋值3.5f"); }else{ screen = newScreen; } screen = newScreen; cpu = newCpu; cem = newCem; System.out.println("有参的构造方法执行啦!"); } public static void main(String[] args) { Shouji shouji = new Shouji(); Shouji.shouji2 = new Shouji(1.5f,1.4f,2.0f); }}
4 回答
慕工程6256650
TA贡献4条经验 获得超4个赞
Shouji . shouji2 = new Shouji(1.5f,1.4f,2.0f) 你多了一个点了
Shouji shouji2 = new Shouji(1.5f,1.4f,2.0f)
啊咿呀
TA贡献14条经验 获得超5个赞
if(newScreen<3.5f){
screen=3.5f
}else{
screen=newScreen
}
cup=newCpu
cem=newCem
刚刚写错了,你写了判断参数错了。条件中也没有给判断后的参数赋值。判断以后你有将newSreen又赋值给了screen这个判断就显得没有意义了。所以得删掉判断以后的screen=newSreen
添加回答
举报
0/150
提交
取消