Java是一種面向對象的編程語言,下面是一些基本的代碼示例:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
public class MyClass {
public static void main(String[] args) {
MyClass myObject = new MyClass();
myObject.myMethod();
}
public void myMethod() {
System.out.println("This is my method!");
}
}
public class MyProgram {
public static void main(String[] args) {
int x = 5;
if (x > 0) {
System.out.println("x is positive.");
} else {
System.out.println("x is negative or zero.");
}
}
}
public class MyProgram {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.println("Iteration: " + i);
}
}
}
public class MyProgram {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
for (int i = 0; i < numbers.length; i++) {
System.out.println("Number: " + numbers[i]);
}
}
}
這些只是一些基本的示例,Java是一種非常強大和靈活的編程語言,可以用于開發各種類型的應用程序。