Now you can Subscribe using RSS

Submit your Email

2015/04/14

a++ 與 ++a

asd


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import org.junit.Test;

/**
 * @author Jrtou
 * @since 2015/04/14
 * 
 * a++ 與  ++a  
 * 
 * 差異在先加和後加的觀念
 */
public class Count {
 /**
  * a++
  * 此方法print 列印出數值為 100
  */
 @Test
 public void count(){
  int a = 100;
  System.out.println("Count");
  System.out.println(a++);
  System.out.println("");
 }
 /**
  * ++a
  * 此方法print  列印出數值為  101
  */
 @Test
 public void count2(){
  int a = 100;
  System.out.println("Count2");
  System.out.println(++a);
  System.out.println("");
 }
 /**
  * a++
  * 此方法print  列印出a數值為101  b數值為100
  */
 @Test
 public void count3(){
  int a = 100;
  int b = a++;
  System.out.println("Count3");
  System.out.println(b);
  System.out.println(a);
  System.out.println("");
 }
 /**
  * ++a
  * 此方法print  列印出a數值為101  b數值為101
  */
 @Test
 public void count4(){
  int a = 100;
  int b = ++a;
  System.out.println("Count4");
  System.out.println(b);
  System.out.println(a);
 }

}

0 意見:

張貼留言

Coprights @ 2016, Blogger Templates Designed By Templateism | Templatelib