Q1. Write a program that prints “Hello, World!”?
public class HelloWorld
{
public static void main(String[] args)
{
[Link]("Hello, World!");
}
}
Q2. Write a program to compare two numbers using relational operators.
public class OperatorsExample {
public static void main(String[] args) {
int num1 = 10, num2 = 5;
[Link]("Sum: " + (num1 + num2));
[Link]("Difference: " + (num1 - num2));
// Relational operators
[Link]("num1 is greater than num2: " + (num1 >
num2));
// Logical operators
boolean condition = (num1 > 0 && num2 < 10);
[Link]("Both conditions are true: " + condition);
}
}
Q3. Write a program to find the largest of three numbers using if-else?
// If-else example
public class ControlFlowExample {
public static void main(String[] args) {
int a = 10, b = 20, c = 5;
if (a > b && a > c) {
[Link]("a is the largest");
} else if (b > c) {
[Link]("b is the largest");
} else {
[Link]("c is the largest");
}
}
}