为什么最后报错显示 shiJi cannot be resolved to a variable 。

package 临时;
import java.util.Scanner;
public class xioafei {
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		System.out.print("请输入您的消费总额:");
		int zongE=input.nextInt();
		System.out.println();
        System.out.println("请出示您的会员卡:");
        int huiYuan=input.nextInt();
        if(huiYuan==1)
        {
        	double shiJi=zongE*0.6;
        	if(huiYuan==2)
        	{
        	     shiJi=zongE*0.7;
        		if(huiYuan==3)
        		{
        			  shiJi=zongE*0.8;
        			if(huiYuan==4)
        			{
        				 shiJi=zongE*0.85;
        				if(huiYuan==5)
        				{
        					  shiJi=zongE*0.9;
        					if(huiYuan==6)
        					{
        					 shiJi=zongE*0.95;
        					}
        				}
        			}
        		}
        	}
        }
        double zheKou=zongE-shiJi;
        System.out.println("消费总金额为"+zongE+"元,实际支付"+shiJi+"元,折后为"+zheKou+"元。");
}
}


苏文进
浏览 1501回答 1
1回答

李晓健

虽然这是一个java题,我就斗胆回答一下,double shiJi=zongE*0.6;  应该放到 if的最外面,应该是变量作用域的问题
打开App,查看更多内容
随时随地看视频慕课网APP