Sunteți pe pagina 1din 32

WEB

DESIGN
LAB
Submitted By
Vagisha Barwal
CSE-4th yr
15507
EXPERIMENT-1(a)
AIM- Write a program to print WELCOME
PROGRAM-
class abc
{
public static void main(String args[])
{
System.out.println("welcome");
}
}
OUTPUT
EXPERIMENT-1(b)
AIM-Write a program to add two numbers
PROGRAM-
class add
{
public static void main(String args[])
{
int a=10;
int b=20;
int c=a+b;
System.out.println("a+b= " +c);
}
}
OUTPUT
EXPERIMENT-1(c)
AIM-Write a program to find larger of two numbers
PROGRAM-
class larger
{
public static void main(String args[])
{
int a=10;
int b=20;
if(a>b)
{System.out.println("larger no is ="+a);}
else
{
if(b>a)
{
System.out.println("larger no is ="+b);}
}
}
}
OUTPUT
EXPERIMENT-1(d)
AIM-Write a program to find largest of three
numbers
PROGRAM-
class larger3
{
public static void main(String args[])
{

int a=400;
int b=20;
int c= 30;

if(a>b&&a>c)
{
System.out.println(" larger number is = "+a);
}
else if(b>a&&b>c)
{
System.out.println("b is the larger number");
}
else
{
System.out.println("c is the larger number");
}
}
}
OUTPUT
EXPERIMENT-1(e)

AIM-Write a program to find square root of two


numbers
PROGRAM-
import java.lang.Math;

class squareroot
{
public static void main (String args[])
{
int a=100;
double b;
b=Math.sqrt(a);
System.out.print("sqroot="+b);
}
}
OUTPUT
EXPERIMENT-2(a)
AIM-Write a program to sort a 1-d array
PROGRAM-
class array
{
public static void main(String args[])
{
int arr[]={20,50,10,5,15};
int a = arr.length;
for(int i=0;i<a;i++)
{
System.out.println(+arr[i]);
}
System.out.println("/n");
for(int i=0;i<a;i++)
{
for(int j=i+1;j<a;j++)
{
if(arr[i]<arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.print("sorted list:");
for(int i=0;i<a;i++)
{
System.out.println(+arr[i]);
}
System.out.print("");
}
}
OUTPUT
EXPERIMENT-2(b)
AIM-Write a program to divide the elements of two
2-D arrays
PROGRAM-
class div
{
public static void main(String arg[])
{
int a[][]={{4,15,12},{27,10,14}};
int b[][]={{2,5,6},{9,5,7}};
int c[][]=new int[2][3];
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]/b[i][j];
System.out.print(+c[i][j]);
}
}}}
OUTPUT
WEB
DESIGN
LAB
Submitted By
Kritika Datta
CSE-4th yr
12407
EXPERIMENT-2(c)
AIM-Write a program to add the elements of two
2-D arrays

PROGRAM-

class a
{
public Static void main(String args[])
{
int a[][]={{2,3,4},{5,6,7}};

int b[][]={{1,2,3},{4,5,6}};

int c[][]=new int[2][3];

for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];

System.out.print(+c[i][j]);
}
}
}
OUTPUT
EXPERIMENT-2(d)
AIM-Write a program to print the Fibonacci series
using an array

PROGRAM-

class f
{
public static void main(String args[])
{
int a[]=new int[10];

a[0]=0;

a[1]=1;

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

{
a[i+2]=a[i]+a[i+1];

System.out.println(+a[i]);

}
}
}
OUTPUT
EXPERIMENT-3
AIM-Write a program to implement various
operations on string

PROGRAM-
class string
{
public static void main(String args[])
{
String s,s2,c;
int a,d;
char b;
String s1=new String("java");
String s3=new String("string");
s=s1.toLowerCase();
s2=s1.toUpperCase();
System.out.println("replace the letter by =" +s1.replace ('a','A'));
System.out.println(" strings are equal or not =" +s1.equals(s));
System.out.println("strings are equal or not =" +s1.equalsIgnoreCase(s));
a=s1.length();
b=s1.charAt(2);
c=s1.concat(s3);
d=s1.indexOf('a');
System.out.println("lowercase value is =" +s);
System.out.println("uppercase value is =" +s2);
System.out.println("length =" +a);
System.out.println("charat(2) =" +b);
System.out.println("concat =" +c);
System.out.println("indexof(a) ="+d);
}
}
OUTPUT
EXPERIMENT-4(a)
AIM-Write a program to implement inheritance
PROGRAM-

class a
{
int i,j;
void show()
{
System.out.println("i & j" +i+""+j);
}}
class b extends a
{
int k;
void add()
{
System.out.println("result=" +(i+j+k));
}
}
class inheritance
{
public static void main(String args[])
{
a superob= new a();
b subob=new b();
superob.i=10;
superob.j=20;
subob.k=30;
subob.add();
}
}
OUTPUT
EXPERIMENT-4(b)
AIM-Write a program to implement overloading
PROGRAM-
class a
{
int k,l;
void area(int i)
{
k=i*i;
System.out.println("area of square =" +k);
}
void area(int i, int j)
{
l=i*j;
System.out.println("area of rectangle =" +l);
}
}

class ovload
{
public static void main(String args[])
{
a ob=new a();
ob.area(3);
ob.area(2,4);
}
}
OUTPUT
EXPERIMENT-4(c)
AIM-Write a program to implement overriding
PROGRAM-

class a
{
int i,j;
a (int a,int b)
{
i=a;
j=b;
}
void show()
{
System.out.println("i&j=" +i+","+j);
}
}
class b extends a
{
int k;
b(int a,int b,int c)
{
super(a,b);
k=c;
}
void show()
{
System.out.println("k=" +k);
super.show();
}}
class override
{

public static void main(String args[])


{

b subob=new b(1,2,3);

subob.show();
}
}
OUTPUT

S-ar putea să vă placă și