[Java Grammar Basics] AcWing 609. Salary (Java Edition) Solution

table of Contents

1. Title

Please write a program that can read an employee’s employee number, total working hours (hours) and hourly salary this month, and output his pay slip, which includes the employee number and employee’s monthly income.

Input format The
input consists of two integers and a floating point number, which represent the employee number, working hours and hourly salary respectively.

Each number occupies one line.

Output format There are
two lines of output. The format of the first line is "NUMBER = X", where X is the employee number.

The format of the second line is "SALARY = U$ Y", where Y is the employee's monthly income, with two decimal places.

Data range
1≤employee number≤100,
1≤total working hours≤200,
1≤hourly salary≤50
Input example:

25
100
5.50

Sample output:

NUMBER = 25
SALARY = U$ 550.00

2. Code

import java.util.Scanner;
import java.text.DecimalFormat;

public class Main
{
    
    
    public static void main(String[] args)
    {
    
    
        Scanner cin=new Scanner(System.in);
        int id,time;
        double wage;
        id=cin.nextInt();
        time=cin.nextInt();
        wage=cin.nextDouble();
        double Y=time*wage;
        DecimalFormat df=new DecimalFormat("###.00");
        System.out.println("NUMBER = "+id);
        System.out.println("SALARY = U$ "+df.format(Y));
    }
}

Guess you like

Origin blog.csdn.net/weixin_45629285/article/details/109345278