报错了一个已经定义了的变量

import java.util.Scanner;

public class test11{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);

    //键盘录入price,month,seat;
    System.out.println("请输入机票的原价");
    int price = sc.nextInt();
    System.out.println("请输入机票的月份");
    int month = sc.nextInt();
    System.out.println("请输入机票的舱位 0:头等舱 1:经济舱");
    int seat = sc.nextInt();
    double reprice=reprice(price,month,seat);
    System.out.println(reprice);
    
    //判断是淡季还是旺季    
}
public static double reprice(int price,int month,int seat){
    //旺季 头等9折,经济8.5
    if(month>=5&&month<=10){
        if(seat==0)//头等舱
        {
            double reprice1=price*0.9;
        }else if(seat==1){
            double reprice1=price*0.85;
        }else{
            System.out.println("错误舱位Error");
        }    
    }else if((month<=4&&month>0)||(month>10&&month<=12)){
        //淡季 头等7折,经济6.5折
        if(seat==0)//头等舱
        {
            double reprice1=price*0.7;
        }else if(seat==1){
            double reprice1=price*0.65;
        

img


}else{
System.out.println("错误舱位Error");
}
}else{
System.out.println("错误月份Error");
}
return reprice1;

}

}

reprice1只是if代码块中的局部变量,return的地方是访问不到的啊。把 double reprice1变量定义放到函数开头吧。

public static double reprice(int price,int month,int seat){
    //旺季 头等9折,经济8.5
    double reprice1 = 0;
    if(month>=5&&month<=10){
        if(seat==0)//头等舱
        {
            double reprice1=price*0.9;
        }else if(seat==1){
            double reprice1=price*0.85;
        }else{
            System.out.println("错误舱位Error");
        }    
    }else if((month<=4&&month>0)||(month>10&&month<=12)){
        //淡季 头等7折,经济6.5折
        if(seat==0)//头等舱
        {
           reprice1=price*0.7;
        }else if(seat==1){
           reprice1=price*0.65;
}else{
System.out.println("错误舱位Error");
}
}else{
System.out.println("错误月份Error");
}
return reprice1;
}
}