问个关于JAVA最简单的问题

来源:百度知道 编辑:UC知道 时间:2024/06/01 02:56:48
public class PartArea2
{
int a = 10;
public static void main(String[] args)
{//main方法开始
int a = 15;
int b = 2;
if(a == 15)
{//条件块开始
double c = 2;//c是可用的
System.out.println(a + "/" + c + "=" + (a/c));
System.out.println("the value a is " + a);//a是可用的
}//条件块结束
//System.out.println("the value c is " + c);//在这里c已经不再可用
System.out.println(a + "/" + b + "=" + (a/b));
System.out.println(a + "%" + b + "=" + (a%b));
}//main方法结束
}
请问一下~程序执行完后a的值是等于10还是等于15?
我的意思是说程序运行完后a是值~不是程序里面输出a的值

可将main方法外的那个a(即第3行int a = 10;)注释掉,因为这个变量声明后代码编译执行过程中根本就没用到过,这样就明了啦。

15

你要明白这个程序中有2个a,一个是在main里,一个在main外,里边的那个肯定是15没变,外边的那个也没变,是10