import [Link].
*;
class program1
{
Public static void main(String args[])
{
[Link](“Welcome to Java”);
}
}
----------------------------------------------------------------------------------------------------------------
Output
Welcome to Java
----------------------------------------------------------------------------------------------------------------
import [Link];
public class AddTwoNumbers
{
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);
// Getting two numbers from the user
[Link]("Enter first number: ");
int num1 = [Link]();
[Link]("Enter second number: ");
int num2 = [Link]();
// Adding two numbers
int sum = num1 + num2;
// Displaying the result
[Link]("The sum is: " + sum);
}
}
----------------------------------------------------------------------------------------------------------------
Output
Enter first number: 10
Enter second number: 20
The sum is: 30
----------------------------------------------------------------------------------------------------------------
import [Link];
public class AddTwoNumbersUsingMethod {
// Method to add two numbers
public static int add(int a, int b)
{
return a + b;
}
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);
// Take two numbers from the user
[Link]("Enter first number: ");
int num1 = [Link]();
[Link]("Enter second number: ");
int num2 = [Link]();
// Call the method
int result = add(num1, num2);
// Display result
[Link]("The sum is: " + result);
}
}
----------------------------------------------------------------------------------------------------------------
Output
Enter first number: 12
Enter second number: 8
The sum is: 20
----------------------------------------------------------------------------------------------------------------
import [Link];
public class PrimeCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
boolean isPrime = true;
if (n < 2) {
isPrime = false;
} else {
for (int i = 2; i <= [Link](n); i++) {
if (n % i == 0) {
isPrime = false;
break;
}
}
}
if (isPrime)
[Link](n + " is a prime number.");
else
[Link](n + " is NOT a prime number.");
[Link]();
}
}
Output
If n = 8
Enter a number: 8
8 is NOT a prime number.
If n = 7
Enter a number: 7
7 is a prime number.