Closed. This question is not reproducible or was caused by typos。它当前不接受答案。
想改善这个问题吗?更新问题,以使溢出。
3个月前关闭。
on-topic
我正在尝试做一个大学活动,其中涉及编写以下程序。我在出现
我是Java的新手,在这里我真的不明白我做错了什么,因为相同的赋值在if语句中正确地起作用,而在else语句中却不正确。
有人可以帮我吗?
想改善这个问题吗?更新问题,以使溢出。
3个月前关闭。
on-topic
我正在尝试做一个大学活动,其中涉及编写以下程序。我在出现
else (employeetype == 2) {
的第27行不断收到错误,错误如下The left-hand side of an assignment must be a variable Syntax error, insert "AssignmentOperator Expression" to complete Assignment Syntax error, insert ";" to complete Statement
。我是Java的新手,在这里我真的不明白我做错了什么,因为相同的赋值在if语句中正确地起作用,而在else语句中却不正确。
有人可以帮我吗?
import java.util.*;
public class TaskFive {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("Please type 1 if you are hourly rated or 2 if you are a salesperson.");
double employeetype = console.nextDouble();
double pay;
if (employeetype == 1) {
System.out.println("Please enter your hourly rate:");
double hourly = console.nextDouble();
System.out.println("Please enter the total hours you worked:");
double hoursworked = console.nextDouble();
if (hoursworked > 40) {
double overtimepay = hoursworked - 40;
pay = (overtimepay * (hourly * 1.5)) + (40 * hourly);
}
else {
pay = (hoursworked * hourly);
}}
else (employeetype == 2) {
System.out.println("Please enter your commission rate as a decimal:");
double comrate = console.nextInt();
System.out.println("Please enter your sales value:");
double sales = console.nextInt();
pay = 500 + (sales * comrate);
}
double tax = (pay*.3);
double netsalary = pay - tax;
System.out.println("Tax: " + tax);
System.out.println("Net Salary: " + netsalary);
}
}
最佳答案
您好朋友在“ if else”语句中,“ if”可以检查条件,而“ else”不能检查条件,它仅执行statement.so如果要在“ if”之后检查“ else”中的条件,则必须更改它到下面的代码
else if (employeetype == 2)
关于java - 作业的左侧必须是变量? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60963638/