zoukankan      html  css  js  c++  java
  • java基础编程题

     1. 某公司每月标准上班时间是160小时,每小时工资是30元。

    如果上班时间超出了160小时,超出部分每小时按1.5倍工资发放。请编写程序计算员工月工资。

    package com.num2.lianxi;
    
    import java.util.Scanner;
    
    public class Lianxi3 {
        public static void main(String[] args){
            //int t=1613;  //表示实际工作的时间
            Scanner sc=new Scanner(System.in);
            System.out.println("亲,输入t的值:" );
            int t=sc.nextInt();
            int c=0;//超出160个小时的时间
            int gz;
            if(t<=160){
                gz=t*30;
                System.out.println("他的工资为:"+gz);
    
            }
            else if(t>160){
                c=t-160;
                gz=160*30+c*45;
                System.out.println("他的工资为:"+gz);
            }
        }
    
    
        }

    2. 已知某年某月,请输出这个月共有多少天。(if语句)

    /** 判断2009年是闰年还是平年。

     *提示:

     *闰年的条件是符合下面二者之一:(1)年份能被4整除,但不能被100整除;(2)能被400整除。

     **/

    package com.num2.lianxi;
    
    import java.util.Scanner;
    
    public class Lianxi4 {
        //判断是闰年还是平年
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("亲,输入年份:");
            System.out.println("亲,输入月份:");
            int t = sc.nextInt();
            int y = sc.nextInt();
            if (t % 4 == 0 && t % 100 != 0 || t % 400 == 0) {
                System.out.println("该年为闰年");
                if (y == 2) {
                    System.out.println("该月有29天");
                } else if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
                    System.out.println("该月有31天");
                } else if (y == 4 || y == 6 || y == 9 || y == 11) {
                    System.out.println("该月有30天");
                }
            } else {
                System.out.println("该年为平年");
    
                if (y == 2) {
                    System.out.println("该月有28天");
                } else if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
                    System.out.println("该月有31天");
                } else if (y == 4 || y == 6 || y == 9 || y == 11) {
                    System.out.println("该月有30天");
                }
            }
    
        }
    }
    /*
    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){      //简便方法
                        System.out.println("该月有31天");
                    }
                    else if(y==4||y==6||y==9||y==11){
                        System.out.println("该月有30天");
                    }
                    else{
                        if((t%4==0)&&(t%100!=0)||(t%400==0))
                            System.out.println(t+"年是闰年,该月有29天");
                        else
                            System.out.println(t+"年是闰年,该月有28天");
                    }
    
    */

    3. 根据学生成绩,打印学生考试等级。

    [90,100]    

    [80,90)     

    [60,80)     

    [0,60)      

    int  score=89;

    package com.num2.lianxi;
    
    import java.util.Scanner;
    
    public class Lianxi5 {
        //判断成绩 switch case语句
        public static void main(String[] args){
            Scanner sc=new Scanner(System.in);
            System.out.println("亲,输入你的成绩:" );
            int t=sc.nextInt();
            switch(t/10){
                case 10:
                case 9:
                System.out.println("你的成绩是优秀");
                break;
                case 8:
                System.out.println("你的成绩为良好");
                break;
                case 7:
                case 6:
                System.out.println("你的成绩为及格");
                break;
                default:
                    System.out.println("直接不及格!!!!!!");
            }
        }
    }

    4.//计算数字5的阶乘 n! = n*n-1*n-2……*1

    package com.num2.lianxi;

    public class Lianxi6 {
    //计算数字五的阶乘
    public static void main(String[] args){
    int t=5;
    int sum=1;
    int i;
    for(i=1;i<=5;i++){
    sum*=i;
    }
    System.out.println("5的阶乘为:"+sum);
    }
    }

    5. 打印九九乘法表

    package com.num2.lianxi;
    
    public class Lianxi7 {
        //打印九九乘法表
        public static void main(String[] arg){
            int i,j;
            int sum=1;
            for(i=1;i<=9;i++){
                for(j=1;j<=i;j++){
                    sum=i*j;
                    System.out.print(j+"*"+i+"="+j*i+"	");
                }
                System.out.println();
            }
        }
    }
  • 相关阅读:
    WPF中的Command事件绑定
    WPF的EventAggregator的发布和订阅
    IE浏览器如何调试Asp.net的 js代码
    MVVM模式用依赖注入的方式配置ViewModel并注册消息
    SQL处理数组,字符串转换为数组
    C#在函数内部获取函数的参数
    JS判断字符串长度(中文长度为2,英文长度为1)
    .net一般处理程序(httphandler)实现文件下载功能
    SQL分页获取数据
    URI编码解码
  • 原文地址:https://www.cnblogs.com/lxx99/p/10879990.html
Copyright © 2011-2022 走看看