[Go to site: main page, start]

0% found this document useful (0 votes)
5 views4 pages

Java Programs: Basics to Matrix Multiplication

The document contains several simple Java programs demonstrating basic programming concepts. It includes programs to print 'Hello, World!', calculate the sum of two numbers, find the maximum of three numbers, determine if a number is even or odd, and perform matrix multiplication. Each program is encapsulated in a class named 'Message' with a main method.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Java Programs: Basics to Matrix Multiplication

The document contains several simple Java programs demonstrating basic programming concepts. It includes programs to print 'Hello, World!', calculate the sum of two numbers, find the maximum of three numbers, determine if a number is even or odd, and perform matrix multiplication. Each program is encapsulated in a class named 'Message' with a main method.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]();

}
}

You might also like