JAVA PROGRAMS
//Simple program to print hello world
class Message
public static void main(String arg[])
[Link]("Hello, World!");
//Program to find sum of two numbers
class Message
public static void main(String arg[])
int num1 = 10;
int num2 = 20;
int sum = num1 + num2;
[Link]("Sum: " + sum);
//Program to find maximun of 3 numbers
class Message
public static void main(String arg[])
int a = 10, b = 20, c = 15;
int max = a;
if (b > max)
{
max = b;
if (c > max)
max = c;
[Link]("Maximum: " + max);
//Program to find the given number is even or odd
class Message
public static void main(String arg[])
int number = 7; // Change this value to test different numbers
if(number % 2 == 0)
[Link](number + " is even.");
else
[Link](number + " is odd.");
}
//Program to find the product of two matrices
class Message
public static void main(String arg[])
// First matrix (2x3)
int[][] matrix1 = { {1, 2, 3}, {4, 5, 6} };
// Second matrix (3x2)
int[][] matrix2 = { {7, 8}, {9, 10}, {11, 12} };
// Result matrix (2x2)
int[][] result = new int[2][2];
// Matrix multiplication
for(int i=0; i<2; i++) {
for(int j=0; j<2; j++) {
for(int k=0; k<3; k++) {
result[i][j] += matrix1[i][k] * matrix2[k][j];
// Display result
[Link]("Resultant Matrix:");
for(int i=0; i<2; i++)
for(int j=0; j<2; j++)
[Link](result[i][j] + " ");
[Link]();
}
}