java basic programming problems

Posted by Birdmansplace on Sat, 09 Nov 2019 19:24:58 +0100

1. The standard working time of a company is 160 hours per month, and the hourly wage is 30 yuan.

If the working time exceeds 160 hours, the excess part shall be paid 1.5 times of the wage per hour. Please write a program to calculate the employee's monthly salary.

 

package com.num2.lianxi;

import java.util.Scanner;

public class Lianxi3 {
    public static void main(String[] args){
        //int t=1613;  //Represents the actual working time
        Scanner sc=new Scanner(System.in);
        System.out.println("Parent input t Value:" );
        int t=sc.nextInt();
        int c=0;//Over 160 hours
        int gz;
        if(t<=160){
            gz=t*30;
            System.out.println("His salary is:"+gz);

        }
        else if(t>160){
            c=t-160;
            gz=160*30+c*45;
            System.out.println("His salary is:"+gz);
        }
    }


    }

2. Given a month of a year, please output the total number of days of the month. (if statement)

/**Determine whether 2009 is a leap year or a normal year.

* prompt:

The condition of * leap year is one of the following two conditions: (1) the year can be divided by 4, but cannot be divided by 100; (2) it can be divided by 400.

 **/

 

package com.num2.lianxi;

import java.util.Scanner;

public class Lianxi4 {
    //Determine leap year or normal year
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Parent, enter year:");
        System.out.println("Parent, enter month:");
        int t = sc.nextInt();
        int y = sc.nextInt();
        if (t % 4 == 0 && t % 100 != 0 || t % 400 == 0) {
            System.out.println("The year is leap year");
            if (y == 2) {
                System.out.println("There are 29 days in the month");
            } else if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
                System.out.println("There are 31 days in the month");
            } else if (y == 4 || y == 6 || y == 9 || y == 11) {
                System.out.println("There are 30 days in the month");
            }
        } else {
            System.out.println("It's the year of the year of the year");

            if (y == 2) {
                System.out.println("There are 28 days in the month");
            } else if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
                System.out.println("There are 31 days in the month");
            } else if (y == 4 || y == 6 || y == 9 || y == 11) {
                System.out.println("There are 30 days in the month");
            }
        }

    }
}
/*
if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){      //Simple method
                    System.out.println("31 days of the month ");
                }
                else if(y==4||y==6||y==9||y==11){
                    System.out.println("30 days of the month ");
                }
                else{
                    if((t%4==0)&&(t%100!=0)||(t%400==0))
                        System.out.println(t+"The year is a leap year with 29 days in the month);
                    else
                        System.out.println(t+"The year is a leap year with 28 days in the month);
                }

*/

3. Print the test grade of students according to their scores.

[90100] excellent

[80,90]

In [60,80]

[0,60] difference

int  score=89;

 

package com.num2.lianxi;

import java.util.Scanner;

public class Lianxi5 {
    //Judgement score switch case Sentence
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        System.out.println("Pro, enter your score:" );
        int t=sc.nextInt();
        switch(t/10){
            case 10:
            case 9:
            System.out.println("Your grades are excellent");
            break;
            case 8:
            System.out.println("Your grades are good");
            break;
            case 7:
            case 6:
            System.out.println("You passed the grade");
            break;
            default:
                System.out.println("Fail directly!!!!!!");
        }
    }
}

 

4. / / calculate the factorial n of number 5! = n * n-1 * n-2 *1

package com.num2.lianxi;

public class Lianxi6 {
//Calculate the factorial of number five
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 ("the factorial of 5 is:" + sum);
}
}

5. Print the multiplication table

 

package com.num2.lianxi;

public class Lianxi7 {
    //Print multiplication table
    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+"\t");
            }
            System.out.println();
        }
    }
}

Topics: Java