0% found this document useful (0 votes)
2 views19 pages

Source Code

The document contains multiple Java source code examples demonstrating basic programming concepts such as printing messages, arithmetic operations, calculating factorials, generating Fibonacci series, handling user input for employee details, checking for palindromes, calculating rectangle area and perimeter, and performing matrix multiplication. Each code snippet is followed by its corresponding output. The examples illustrate fundamental Java syntax and logic.

Uploaded by

rajtiamil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views19 pages

Source Code

The document contains multiple Java source code examples demonstrating basic programming concepts such as printing messages, arithmetic operations, calculating factorials, generating Fibonacci series, handling user input for employee details, checking for palindromes, calculating rectangle area and perimeter, and performing matrix multiplication. Each code snippet is followed by its corresponding output. The examples illustrate fundamental Java syntax and logic.

Uploaded by

rajtiamil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

source code:-1

class Bsc

public static void main(String args[])

[Link]("welcome to java language");

[Link]("welcome to java lab");

}
output:-

welcome to java language

welcome to java lab


source code:-2

class AOP

public static void main(String args[])

int a=50,b=25;

[Link]("a="+a);

[Link]("b="+b);

[Link]("a+b="+(a+b));

[Link]("a-b="+(a-b));

[Link]("a*b="+(a*b));

[Link]("a/b="+(a/b));

}
output:-

a=50

b=25

a+b=75

a-b=25

a*b=1250

a/b=2
source code:-3

class FACT

public static void main(String args[])

int number=10;

int factorial=number;

for (int i=(number-1);i>1;i--)

factorial=factorial*1;

[Link]("factorial of a number is:"+factorial);

}
output:-

factorial of a number is:10


source code:-4

import [Link];

class Fibonacci

public static void main(String arg[])

int n,a=0,b=0,c=1;

Scanner s=new Scanner ([Link]);

[Link]("enter value of n:");

n=[Link]();

[Link]("Fibonacci series:");

for (int i=1;i<n;i++);

a=b;

b=c;

c=a+b;

[Link](a+" ");

}
output:-

enter value of n:

10

Fibonacci series:

0,1,1,2,3,5,8,13,21,34
source code:-5

import [Link];

class Employee

public static void main (String args[])

Scanner scemp=new Scanner ([Link]);

[Link]("enter employee id number:");

int empid=[Link]();

[Link]("enter employee name:");

String empname=[Link]();

[Link]("empid:"+empid+"empname:"+empname);

}
output:-

enter employee id number:

145

enter employee name:

bsc

empid:145empname:bsc
source code :-6

import [Link];

class palindromenumber

public static void main(String args[])

int number,reversed,original;

Scanner sc=new Scanner([Link]);

[Link]("enter the number");

number=[Link]();

original=number;

reversed=0;

while(number!=0)

int digit=number%10;

reversed=reversed*10+digit;

number=number/10;

if(original==reversed)

[Link](original+"is a palindrome number");

else

{
[Link](original+"is not a palindrome number");

}
output:-

enter the number

121

121is a palindrome number


source code:-7

import [Link];

class Rectangle

public static void main(String args[])

int length,breath,area,perimeter;

Scanner sc=new Scanner([Link]);

[Link]("length of the rectangle=");

length=[Link]();

[Link]("breath of the rectangle=");

breath=[Link]();

area=length*breath;

perimeter=2*(length+breath);

[Link]("area of rectangle="+(area));

[Link]("perimeter of rectangle="+(perimeter));

}
output:-

length of the rectangle=

20

breath of the rectangle=

15

area of rectangle=300

perimeter of rectangle=70
source code:-8

public class matrixmultification

public static void main(String args[])

int[][]matrixA=

{0,2,4},

{4,5,6},

{6,9,3}

int[][] matrixB=

{6,9,3},

{3,4,5},

{1,2,3}

};

int[][] product=new int[3][3];

for(int i=0;i<3;i++)

for(int j=0;j<3;j++)

product[i][j]=0;

for(int k=0;k<3;k++)

{
product[i][j]+=matrixA[i][k]*matrixB[k][j];

[Link]("resultof 3*3 matrix multification:");

for(int i=0;i<3;i++)

for(int j=0;j<3;j++)

[Link](product [i][j]+" ");

[Link]();

}
output:-

resultof 3*3 matrix multification:

10

16

22

45

68

55

66

96

72

You might also like