刚学if else 用的不好 各位大神不要见笑

来源:互联网 发布:网易云音乐数据库 编辑:程序博客网 时间:2024/06/05 02:53
// 输入一个4位数判断一个数是否是玫瑰花数

//(a*a*a*a+b*b*b*b+c*c*c*c+d*d*d*d=i)

import java.util.*;public class HomeWork1 {public static void main(String[] args) {System.out.println("请输入一个四位数的整数:");Scanner sc = new Scanner(System.in);int i = sc.nextInt();int a = i % 10;int b = i / 10 % 10;int c = i / 100 % 10;int d = i / 1000 % 10;if (i >= 1000 && i < 10000) {if ((a * a * a * a + b * b * b * b + c * c * c * c + d * d * d * d) == i) {System.out.println("是玫瑰花数!");} else {System.out.println("不是玫瑰花数!");}} else {System.out.println("你输入的不是四位数的整数!");}}}


// 输入考试分数判断学生的成绩

import java.util.*;public class HomeWork1 {public static void main(String[] args) {System.out.println("请输入成绩:");Scanner sc = new Scanner(System.in);int score = sc.nextInt();if (score < 60) {System.out.println("不及格,再努力!");} else if (score < 70) {System.out.println("及格!");} else if (score < 80) {System.out.println("良好!");} else if (score <= 100) {System.out.println("优秀!");} else {System.out.println("输入错误!");}}}


// 输入一个年份判断是否是闰年
//(能被4整除不能被100整除或者能被400整除的数)

import java.util.*;public class HomeWork1 {public static void main(String[] args) {System.out.println("请输入年份:");Scanner sc = new Scanner(System.in);int i = sc.nextInt();if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {System.out.println("是闰年!");} else {System.out.println("不是闰年!");}}}


/* 个人所得税计算器
个人所得税税率表一(工资、薪金所得适用)
  级数 全月应纳税所得额 税率(%)
  1 不超过1500元的 3
  2 超过1500元至4500元的部分 10
  3 超过4500元至9000元的部分 20
  4 超过9000元至35000元的部分 25
  5 超过35000元至55000元的部分 30
  6 超过55000元至80000元的部分 35
  7 超过80000元的部分 45

*/

import java.util.*;public class HomeWork1 {public static void main(String[] args) {System.out.println("请输入你的工资:");Scanner sc = new Scanner(System.in);int wage = sc.nextInt();int i = wage - 3500;double a = 0;if (i <= 0) {System.out.println("工资连3500都不到,不用交税了!");} else if (i <= 1500) {a = i * 0.03;} else if (i <= 4500) {a = 1500 * 0.03 + (i - 1500) * 0.1;} else if (i <= 9000) {a = 1500 * 0.03 + (4500 - 1500) * 0.1 + (i - 4500) * 0.2;} else if (i <= 35000) {a = 1500 * 0.03 + (4500 - 1500) * 0.1 + (9000 - 4500) * 0.2+ (i - 9000) * 0.25;} else if (i <= 55000) {a = 1500 * 0.03 + (4500 - 1500) * 0.1 + (9000 - 4500) * 0.2+ (35000 - 9000) * 0.25 + (i - 35000) * 0.3;} else if (i <= 80000) {a = 1500 * 0.03 + (4500 - 1500) * 0.1 + (9000 - 4500) * 0.2+ (35000 - 9000) * 0.25 + (55000 - 35000) * 0.3+ (i - 55000) * 0.35;} else {a = 1500 * 0.03 + (4500 - 1500) * 0.1 + (9000 - 4500) * 0.2+ (35000 - 9000) * 0.25 + (55000 - 35000) * 0.3+ (80000 - 55000) * 0.35 + (i - 80000) * 0.45;}System.out.println("你应该交税为:" + a);System.out.println("你交税后的工资为:" + (wage - a));}}


原创粉丝点击