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();
            }
        }
    }
  • 相关阅读:
    ubuntu 16.04 更新后搜狗输入法无法输入中文的问题
    转: 苹果APNS的说明
    转:svn 更新指定文件夹
    转: Java 应用一般架构
    【原创】关于bug反正出现的问题可能
    App开发者博客之: 包建强 (专注移动app开发)
    转: 阿里跨平台移动开发工具Weex
    【原创】存储层设计的一些方法论
    转:车牌的自动截取与识别方案
    转: java web demo的示例
  • 原文地址:https://www.cnblogs.com/lxx99/p/10879990.html
Copyright © 2011-2022 走看看