Here are three concise Java code examples for different purposes:
1. Hello World Program
Copy the codepublic class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
2. Simple Calculator (Addition)
Copy the codeimport [Link];
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter first number: ");
int num1 = [Link]();
[Link]("Enter second number: ");
int num2 = [Link]();
int sum = num1 + num2;
[Link]("The sum is: " + sum);
}
}
3. Check if a Number is Even or Odd
Copy the codeimport [Link];
public class EvenOdd {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
if (number % 2 == 0) {
[Link](number + " is even.");
} else {
[Link](number + " is odd.");
}
}
}
Feel free to adapt these examples to your needs! Let me know if you'd like help with a
specific type of Java program.