在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"};