1.编写程序计算电费:每月用电不超过50度, 每度0.72元; 超过50度时, 超出部分每度1.20元.

来源:百度知道 编辑:UC知道 时间:2024/06/16 10:59:59
2.编写程序:输入一整数给变量X,X小于0时显示-1,X等于0时显示0,X大于0时显示1(要求分别用IF-ENDIF、DO CASE-ENDCASE编写)。
非常感谢大师指导

用if
input x
if x<0 then print “-1”
else
if x=0 then print“ 0”
else
print “1”
end if
用case
input x
select case x
case is < 0
print “-1”
case is = 0
print “0”
case else
print “1”
end select

class exprenses
{
int degree;
static double f;
double fun()
{
if(degree<50)

return f=degree*0.72;

else return f=(degree-50)*1.20+50*0.72;
}
public static void main(String[]args)
{
exprenses p=new exprenses();
p.fun();
System.out.println(f);
}
}
十分就只值这点了