我正面臨一個奇怪的問題。插入變量以最小化代碼
if (c2==c1){
c3 *= 2 ;
System.out.println(c3) ;
.....
}
我想在println語句中插入c3 * 2。但是
if (c2==c1){
System.out.println(c3*2) ;
給了我不同的結果。
這裏是整個代碼:
public static void main(String [] args) {
int c1 = Integer.parseInt(args[0]) ;
int c2 = Integer.parseInt(args[1]) ;
int c3 = Integer.parseInt(args[2]) ;
/* 1 */ if (c1 != c3){
/* 2 */ if (c2==c1){
/* 3 */
/* 4 */ System.out.println(c3 + c2) ;
/* 5 */ c3 *= c2 ;
/* 6 */ }
/* 7 */ }else{
/* 8 */ if (c2==c1){
/* 9 */ c3 *= 2 ;
/* 10 */ System.out.println(c3) ;
/* 11 */ c3 *= c2 ;
/* 12 */ if (c1 < c2) c2 += 7 ;
/* 13 */ else c2 += 5 ;
/* 14 */ }}
/* 15 */ System.out.println(c1+c2+c3) ;
}
.....
}
任何想法?
你能不能先離開的變量聲明?它給你什麼結果? – lbedogni 2010-10-31 09:08:22
這裏是一樣的。你沒有展示一切。 – Bozho 2010-10-31 09:08:45
*什麼*不同的結果,不同於*什麼?*你甚至沒有發佈c3的聲明。請澄清你的問題。 – EJP 2010-10-31 09:10:57