对于java来说,我是初学者。我正在做一个计算机课程,里面有一些编程。我正在做一个让我使用循环和数组等的任务。
任务的一部分是输出员工的总薪酬。我只是想知道如何将此值存储为变量这是我的代码:
for(int position=0; position <hours.length;position=position+1) {
System.out.println("Gross Pay for " +employees[position]+("= ")+hours[position]*Wage[position]);}
我想知道我需要用来将grosspay
分配给变量的代码,因为我必须计算25%的税率,我也不确定该如何做,但如果你可以帮助我第一部分将是辉煌的。我尝试过一些事情,但我无法理解。
我在数组中有工资和小时是的,我也可以只显示我目前的代码。 import java.util.Scanner; 公共课Assignment2 {
public static void main(String[] args) {
//declare array called employees to store the workers names
String employees[]= {"Samuel Patrick","Thomas Hogans","Murray Murphy","Michael Honnan","Anthony Brosnan","Pauline Clancy","Susan Slattery",};
//declare an array called Wage using the double data type to store the employees hourly wage
double Wage[]= {9.25,8.75,8.65,9.45,8.25,9.50,8.75};
//declare an array called hours which will be used to enter employees hours worked
int hours[] = new int[7];
//set up the scanner to allow employees hours worked to be entered
Scanner in = new Scanner(System.in);
//Instruct the user to enter the amount of hours worked
System.out.println("Enter hours worked");
for(int position=0; position <hours.length;position=position+1) {
System.out.print("Employee "+employees[position]);
hours[position] = in.nextInt();
}
for(int position=0; position <hours.length;position=position+1) {
System.out.println("Gross Pay for " +employees[position]+("= ")+hours[position]*Wage[position]);}
{
for(int position=0; position <hours.length;position=position+1);
System.out.print("Total Tax owed for "+employees[position]
}
}
我试过像这样输入
double GrossPay = (employees[position]+hours[position]*Wage[position]);
但这会不断出现错误,这是正确的做法吗?
我知道这可能不是最有效的做事方式,但老师希望这样做。
答案 0 :(得分:1)
看看this page,解释如何在Java中分配变量。
假设你的变量是双倍的,你会得到类似的东西,例如:
double grosspay = 9586.250;
然后你必须用你的公式替换9586.250。