You are on page 1of 14

ROLL NO.

-8716113

PRACTICAL FILE OF
ESSENTIALS OF INFORMATION
TECHNOLOGY
(CSE-314N)

Submitted to: Submitted by:


Mr. Ved prakash Drishti gupta
HOD in CSE Deptt. CSE 6th sem.
Roll no. 8716113

Department of Computer science and Engineering


ROLL NO.-8716113

State Institute of Engineering and Technology


(Nilokheri)
PRACTICAL:-1

AIM:-Write a java program to find the factorial of a number.


class Factorial{
public static void main(String args[]){
inti,fact=1;
int number=4;
for(i=1;i<=number;i++)
{
fact=fact*i;
}
System.out.println("factorial of "+number+"is:"+fact);
}
}
ROLL NO.-8716113

OUTPUT:-
ROLL NO.-8716113

PRACTICAL:-2
AIM:-Write a java program to implement multilevel inheritance.
package MultilevelInheritance;
class Multimain{
public static void main(String args[]){
S3 obj=new S3();
obj.display();
}
}
public class MultilevelInheritance
{
protected String str;
MultilevelInheritance(){
str="Btech-";
}
}
class S1 extends MultilevelInheritance{
S1(){
str=str.concat("CSE");
}
}
class S2 extends S1{
S2(){
str=str.concat("3rd Year");
}
}
class S3 extends S2{
S3(){
str=str.concat("Java Program");
}
void display(){
System.out.println(str);
}
}
ROLL NO.-8716113
ROLL NO.-8716113

OUTPUT:-
ROLL NO.-8716113

PROGRAM:-3
AIM:-Write a java program to implement insertion sort.
package insertion_sort;
public class Insertion_sort {
public static void main(String[] args)
{
int[] a = {12,22,5,13,9};
System.out.println("Before Insertion sort");
printArray(a);
insertionsort(a);
System.out.println("After insertion sort");
printArray(a);
}
public static void insertionsort(intarr[])
{
int n = arr.length;
for(inti =1;i<n;i++)
{
System.out.println("Sort pass number"+(i));
int key=arr[i];
int j = i-1;
while((j>-1 &&arr[j] < key))
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = key;
printArray(arr);
}
}
public static void printArray(int[] array)
{
for(inti =0; i<array.length; i++)
{
System.out.print(array[i] + ",");
}
System.out.println();
}

}
ROLL NO.-8716113

OUTPUT:-
ROLL NO.-8716113

PROGRAM-4
AIM:-Write a java program to implement interface.
interface Itemconstant
{
int code = 1001;
String name = "fan";
}
interface Item extends Itemconstant
{
void display();
}
interface Area
{
final static float pi = 3.14F;
float compute(float x, float y);
}
class rectangle implements Area {
public float compute(float x, float y)
{
return (x * y);
}
}
class circle implements Area {
public float compute(float x, float y)
{
return (pi * x * x);
}
}
class Multiple {
public static void main(String[] args) {
rectangle rect = new rectangle();
circle cir = new circle();
Area area;
area = rect;
System.out.println("Area of rectangle=" + area.compute(10, 20));
area = cir;
System.out.println("Area of circle=" + area.compute(10, 0));
}
}
ROLL NO.-8716113

OUTPUT:-
ROLL NO.-8716113

PROGRAM-5(A)
AIM:-Write a java program to implement pass by value parameters.
public class PassByValue
{
public static void swap(intx,int y)
{
int temp=x;
x=y;
y=temp;
System.out.println("x1="+x);
System.out.println("y1="+y);
}
public static void main(String[] args)
{
int x=45;
int y=36;
swap(x,y);
System.out.println("x2="+x);
System.out.println("y2="+y);
}
}
ROLL NO.-8716113

OUTPUT:-
ROLL NO.-8716113

PROGRAM-5(B)

AIM:-Write a java program to implement reference by parameters.

public class ByReference


{
public static void swap(String s1,String s2)
{
String temp=s1;
s1=s2;
s2=temp;
System.out.println("s1(A)="+s1);
System.out.println("s2(A)="+s2);
}
public static void main(String[] args)
{
String s1="SIET";
String s2="STUDENTS";
swap(s1,s2);
System.out.println("s1(B)="+s1);
System.out.println("s2(B)="+s2);
}
}
ROLL NO.-8716113

OUTPUT:-

You might also like