首页 > 代码库 > Java开发中经典的小实例-(if(参数){}else{})
Java开发中经典的小实例-(if(参数){}else{})
import java.util.Scanner;
public class Calculate {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数字(小于5000):");
int number = input.nextInt();
double sum = 0;
if (number < 500) {
sum = number * 0.05;
System.out.println(sum);
} else if (number > 500 && number <= 2000) {
sum = (number * 0.1) - 25;
System.out.println(sum);
} else if (number > 2000 && number <= 5000) {
sum = (number * 0.15) - 125;
System.out.println(sum);
} else {
System.out.println("请输入正确数字。");
}
}
}
Java开发中经典的小实例-(if(参数){}else{})