public class SimpleJavaCode {
public static void main(String[] args) {
System.out.println("Hello, World!");
int num1 = 5;
int num2 = 10;
int sum = num1 + num2;
System.out.println("Sum of " + num1 + " and " + num2 + " is: " + sum);
String message = "This is a simple Java program.";
System.out.println(message);
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
}
System.out.println();
int[] numbers = {1, 2, 3, 4, 5};
for (int number : numbers) {
System.out.print(number + " ");
}
System.out.println();
String[] names = {"Alice", "Bob", "Charlie"};
for (String name : names) {
System.out.println("Hello, " + name + "!");
}
int result = addNumbers(3, 7);
System.out.println("Result of addition: " + result);
String reversed = reverseString("Hello");
System.out.println("Reversed string: " + reversed);
}
public static int addNumbers(int a, int b) {
return a + b;
}
public static String reverseString(String str) {
StringBuilder reversed = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) {
reversed.append(str.charAt(i));
}
return reversed.toString();
}
}