## 1.局部變量

``````public static void main(String[] args)
{
int a = 5;
if (a < 10)
{
int b = 10;
while (true)
{
int x = a + b;
System.out.println(x);
}
System.out.println(b);
}

}``````
``````

a
a
a
a, b
a, b
a, b
a, b, x
a, b, x
a, b
a, b
a
a

``````

``````public static void main(String[] args)
{
int a = 5;
if (a < 10)
{
int b = 10;
System.out.println(b);
}

if (a < 20)
{
int b = 20;
System.out.println(b);
}
}``````
``````

a
a
a
a, b
a, b
a
a
a
a
a, b
a, b
a

``````

## 2. 參數

``````public static void main(String[] args)
{
int a = 5;
if (a < 10)
{
int b = 10;
while (true)
{
int x = a + b;
System.out.println(x);
}
System.out.println(b);
}

}``````
``````
args
args, a
args, a
args, a
args, a, b
args, a, b
args, a, b
args, a, b, x
args, a, b, x
args, a, b
args, a, b
args, a
args, a

``````

## 3.類中的變量

``````public class Solution
{
public int count = 0;
public int sum = 0;

{
sum = sum + data;
count++;
}

public void remove(int data)
{
sum = sum - data;
count--;
}
}``````
``````

count
count, sum
count, sum
count, sum
count, sum, data
count, sum, data
count, sum, data
count, sum
count, sum
count, sum
count, sum, data
count, sum, data
count, sum, data
count, sum
count, sum

``````

## 4.靜態變量

``ClassName.variableName``

``````public class Solution
{
{
Storage.sum = Storage.sum + data;
Storage.count++;
}

public void remove(int data)
{
Storage.sum = Storage.sum - data;
Storage.count--;
}
}

public class Storage
{
public static int count = 0;
public static int sum = 0;
}``````
``````
Storage.count, Storage.sum
Storage.count, Storage.sum
Storage.count, Storage.sum, data
Storage.count, Storage.sum, data
Storage.count, Storage.sum, data
Storage.count, Storage.sum
Storage.count, Storage.sum
Storage.count, Storage.sum
Storage.count, Storage.sum, data
Storage.count, Storage.sum, data
Storage.count, Storage.sum, data
Storage.count, Storage.sum

Storage.count, Storage.sum
Storage.count, Storage.sum
Storage.count, Storage.sum

``````