新手java练习题100(1-5)
1、编程实现:根据以下函数关系,对输入的X值计算输出对应的y值。
x的值 | 对应y的值 |
---|---|
x<0 | 0 |
0<=x<10 | x |
10<=x<20 | 0.5*x+18 |
x>=20 | 100 |
class test {
public static void main(String[] args) {
double x,y; //定义参数类型
x=0,y=0; //数据初始化
if (x<0) {
y = 0;
} else if (x>=0&&x<10){
y=x;
} else if (x<20&&x>=10){
y=0.5*x+18;
}else if (x>=20){
y=100;
} //判断
System.out.println(y);
//输出
}
}
2、编写程序计算1!+2!+3!+…+n!,并输出计算结果。byGaoshiguo112
import java.util.Scanner;
public class test2 {
public static void main(String[] args){
Scanner scanne