有谁知道为什么java不理解变量"增量"?我的任务是找出用户的服务年限和工资.之后,我将为每个人分配一个增量.但是当我想打印变量"increment"时,java无法识别它.我可以知道为什么吗?
import javax.swing.JOptionPane;
public class Q4 {
public static void main(String[] args) {
int increment;
String yearsString = JOptionPane.showInputDialog(null,
"Please enter your years of service");
String salaryString = JOptionPane.showInputDialog(null,
"Please enter your salary");
int years = Integer.parseInt(yearsString);
double salary = Double.parseDouble(salaryString);
if(years < 10) {
if(salary < 1000.0) {
increment = 100;
}
else if (salary< 2000.0) {
increment = 200;
}
else {
increment = 300;
}
}
else if (years > 10) {
if(salary<1000) {
increment = 200; …Run Code Online (Sandbox Code Playgroud) java ×1