A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© huizhong 中级黑马   /  2016-6-30 00:12  /  1167 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

(1)根据工龄(整数)给员工涨工资(整数),工龄和基本工资通过键盘录入
        (2)涨工资的条件如下:
                [10-15)     +5000
                [5-10)      +2500
                [3~5)       +1000
                [1~3)       +500
                [0~1)       +200
        (3)如果用户输入的工龄为10,基本工资为3000,程序运行后打印格式"您目前工作了10年,基本工资为 3000元, 应涨工资 5000元,涨后工资 8000元"
import java.util.Scanner;
class ZuoYe234 {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入工龄");
                int a = sc.nextInt();
                System.out.println("请输入基本工资");
                int b = sc.nextInt();
                int c=b+5000;
                int d=b+2500;  //int b = 3000;
                int e=b+1000; //int z = b + 5000
                int f=b+500;
                int g=b+200;
                if ( a >= 10 & a <= 15) {
                        System.out.println("您目前工作了"+a+"年,基本工资为"+b+"元, 应涨工资 5000元,涨后工资"+c+"元");
                }else if ( a >= 5 & a < 10) {
                        System.out.println("您目前工作了"+a+"年,基本工资为"+b+"元, 应涨工资 2500元,涨后工资"+d+"元");
                }else if ( a >= 3 & a < 5) {
                        System.out.println("您目前工作了"+a+"年,基本工资为"+b+"元, 应涨工资 1000元,涨后工资"+e+"元");
                }else if (a >= 1 & a < 3) {
                        System.out.println("您目前工作了"+a+"年,基本工资为"+b+"元, 应涨工资 500元,涨后工资"+f+"元");
                }else if (a > 0 & a < 1) {
                        System.out.println("您目前工作了"+a+"年,基本工资为"+b+"元, 应涨工资 200元,涨后工资"+g+"元");
                }else if (a>15) {
                        System.out.println("输入错误");
                }
        }
}

9 个回复

倒序浏览
import java.util.Scanner;                                // 导包
class Test3_if {  
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);        //录入键盘输入对象
                System.out.println("请输入你的工龄");       
                int age = sc.nextInt();                                        //把录入的工龄的结果存储在age里面
               
                //创建两个变量,x用来接收应涨工资,y用来接收涨后工资
                int x = 0;                                               
                int y = 0;
                if (age >= 0 && age <= 15) {
                        System.out.println("请输入你的基本工资");
                        int money = sc.nextInt();                        // 将录入的基本工资的值存储在money当中
                        if (age > 10 && age <= 15) {
                        x = 5000;
                        y = money + x;
                        }else if (age > 5 && age <= 10) {
                        x = 2500;
                        y = money + x;
                        }else if (age > 3 && age <= 5) {
                        x = 1000;
                        y = money + x;
                        }else if (age > 1 && age <= 3) {
                        x = 500;
                        y = money + x;
                        }else if (age >= 0 && age <= 1) {
                        x = 200;
                        y = money + x;
                        }
                        System.out.println("您目前工作了" + age +"年,基本工资是"+ money +"元,应涨工资"+ x +
                                "元,涨后工资" + y +"元");
                }else {
                        System.out.println("你输入的数据有误");
                }

        }
}
这样应该可以了。
回复 使用道具 举报 1 0
[code        ]int z=0;
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入工龄");
                int x = sc.nextInt();
                System.out.println("请输入基本工资");
                int y = sc.nextInt();
                if(x >= 10 && x < 15)         z=5000;
                else if(x >= 5 && x < 10)    z = 2500;
                else if(x >= 3 && x < 5)     z = 1000;
                else if(x >= 1 && x < 3)     z = 500;
                else if (x >= 0 && x < 1)     z = 200;
                else System.out.println("哇,程序不想理你,并向你抛出了一个异常");
                int sum = y + z;
                System.out.println("您目前工作了"+x+"年"+","+"基本工资为"+y+"元"+","+"应涨工资"+z+"元"+","+"涨后工资"+sum+"元");
[/code]
你觉得这样是不是简单些。
回复 使用道具 举报 1 0
import java.util.Scanner;
class Demo_Ti4 {
        public static void main(String[] args) {
                Scanner sc=new Scanner(System.in);
                System.out.println("请输入工龄,需为整数:");
                int a=sc.nextInt();
                System.out.println("请输入基本工资,需为整数:");
                int b=sc.nextInt();
                int c=0;
                if(a<15&&a>=0) {       
                        if (a>=0&&a<1) {
                                c=200;
                        } else if(a>=1&&a<3) {
                                c=500;
                        } else if (a>=3&&a<5) {
                                c=1000;
                        } else if (a>=5&&a<10) {
                                c=2500;
                        } else if (a>=10&&a<15) {
                                c=5000;
                        }
                        System.out.println("您目前工作了"+a+"年,基本工资为"+b+"元,应涨工资"+c+"元,涨后工资"+(b+c)+"元");
                } else {
                        System.out.println("你输入的工龄无相关记录,请输入15以下的自然数工龄");
                }
        }
}
回复 使用道具 举报 1 0
学习了·········
回复 使用道具 举报
月下夜风 发表于 2016-6-30 18:25
import java.util.Scanner;
class Demo_Ti4 {
        public static void main(String[] args) {

是比较简单了.先定义一个以后用到的变量为0是不是可以减少点错误
回复 使用道具 举报
import java.util.Scanner;
class Demo1 {
        public static void main(String[] args){
                Scanner sc=new Scanner(System.in);
                System.out.println("请输入工龄");
                int workAge=sc.nextInt();
                System.out.println("请输入基本工资");
                int basePay=sc.nextInt();
                int pay=basePay;
                if(workAge>=0&&workAge<15){       //判断工龄的是否是正确的工龄
                        if(workAge>=0&&workAge<1){
                                 pay+=200;
                        }else if (workAge>=1&&workAge<3) {
                                        pay+=500;
                        }else if (workAge>=3&&workAge<5) {
                                        pay+=1000;
                        }else if (workAge>=5&&workAge<10) {
                                        pay+=2500;
                        }else  
                                        pay+=5000;
                                System.out.println("您目前工作了"+workAge+"年,基本工资为"+basePay+"元, 应涨工资"+(pay-basePay)+"元,涨后工资"+pay+"元");
                }
                System.out.println("请输入正确的工龄");

        }
}
回复 使用道具 举报
qinxuezilu1314 发表于 2016-6-30 18:57
import java.util.Scanner;
class Demo1 {
        public static void main(String[] args){

厉害厉害呀
回复 使用道具 举报
学习了!!!!!!!!
回复 使用道具 举报
940752944 发表于 2016-6-30 19:02
学习了!!!!!!!!

共同学习,共同进步
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马