在Java中,定義變量的方式有以下幾種:
public void exampleMethod() {
int a = 10;
String b = "Hello";
}
public class ExampleClass {
public int x;
private String y = "World";
}
public class ExampleClass {
public static int count = 0;
public static final String NAME = "Java";
}
public void exampleMethod(int num, String text) {
// 方法體
}
for (int i = 0; i < 10; i++) {
// 循環體
}
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Charlie"};