I am developing a payroll program for my programming class. I need to declare the Int as a double in order to produce the product for number of employees in a department times the average salary for each employee. Can someone take a look at me code and let me know if my double declare is sufficient. Thanks appreciate it.

// Fig 2.2: Product.java
// Printing a line of text with multiple statements.
// Calculate the product of two integers.
import java.util.Scanner; // program uses Scanner

public class Product {

    public static void main(String[] args) {
        // create Scanner to obtain input from command window
        System.out.print("Department Name [enter name]\n");
        System.out.print("Number of Employee's[enter total]\n");
        System.out.print("Employee Salary[enter salary]\n");
        System.out.println("H.R. Department");

        Scanner input = new Scanner(System.in);

        int x; // enter number of employee's
        double y; // enter employee salary
        int result; // product of numbers

        System.out.print("Enter number of Employee's: "); // prompt for input
        x = input.nextInt(); // read first integer

        System.out.print("Enter employee salary:($) "); // prompt for input
        y = input.nextDouble(); // read second integer

        result = (int) (x * y); // calculate product of numbers

        System.out.printf("Product is %d\n", result);

    } //end method main
} //end class Product

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This is a Java program; I think you will be more likely to get help with it if you post it in a Java forum rather than a C++ forum.

This article has been dead for over six months. Start a new discussion instead.