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是一种非常强大和灵活的编程语言,可以用于开发各种类型的应用程序。