JINIA UNI.R.
NO-1277436
MCA-3rd sem Section-F
1./* write a program of print message*/
class MCA { public static void main(String args[]) { [Link]("print"); } }
output
Pg|1
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
2./* write a program for addition*/
class ADD { public static void main(String arg[]) { int a=10,b=20,c; c=a+b; [Link]("addition is="+c); } }
output
Pg|2
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
3./* program to print the fabbonacci series*/
class FIB { public static void main(String arg[]) { int a=0,b=1,c,n; c=a+b; [Link]("fib series is="); [Link]("\t" +a); [Link]("\t" +b); for(n=10;n>c;n--) { c=a+b;a=b;b=c; [Link]("\t"+c); } } }
output
Pg|3
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
4./*program to show the use of static*/
class counter { static int count=0; counter() { count++; [Link](count); } public static void main(String arg[]) { counter c1=new counter(); counter c2=new counter(); counter c3=new counter(); } }
output
Pg|4
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
5./* program to show the use of commandline arguments*/
class commandline { public static void main(String arg[]) { int count; count=[Link]; [Link]("no of argument" +count); for(int i=0;i<count;i++) { [Link]("arguments are"); [Link]("arg["+i+"]="+arg[i]); } } }
output
Pg|5
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
6./* wap to find the factorial of a no*/
class r { int fact(int n) { if(n==0) return 1; else return n*fact(n-1); } } class factorial { public static void main(String args[]) { int f; r obj=new r(); f=[Link](5); [Link]("Factorial is="+f); } }
Output
Pg|6
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
7./*program to find out the area*/
class rectangle { int length,breadth; void setdata(int l,int b) { length=l; breadth=b; } } class Area { public static void main(String arg[]) { int area; rectangle obj1=new rectangle(); [Link](10,20); area=[Link]*[Link]; [Link]("area="+area); } }
output
Pg|7
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
8./*wap to represent matrix by using array*/
class Array { public static void main(String args[]) { int arr[][]=new int[3][]; arr[0]=new int[3]; arr[1]=new int[3]; arr[2]=new int[3]; int i,j,k; for(i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { arr[i][j]=k; } } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { [Link](+ arr[i][j] + "\t"); } [Link](); } } }
output
Pg|8
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
9./*program of multiplication of an array*/
class armul { public static void main(String arg[]) { int i,j,k; int a[][]={{1,2,3},{2,3,4},{3,4,5}}; int b[][]={{2,5,1},{4,6,7},{6,7,8}}; int c[][]=new int[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k++) { c[i][j]=c[i][j]+a[i][j]*b[i][j]; } } } for(i=0;i<3;i++) { for(j=0;j<3;j++) [Link](c[i][j] + "\t"); [Link](); } } }
output
Pg|9
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
10. /*WAP of passing object as an argument*/
class Demo { int a,b; Demo(int x,int y) { a=x; b=y; } boolean equals(Demo ob) { if(ob.a==a && ob.b==b) return true; else return false; } } class Demomain { public static void main(String args[]) { Demo obj1=new Demo(10,20); Demo obj2=new Demo(30,40); Demo obj3=new Demo(10,20); [Link]("obj1==obj2="+[Link](obj2)); [Link]("obj2==obj3="+[Link](obj3)); [Link]("obj1==obj3="+[Link](obj3)); } }
output
Pg|10
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
11./*program to show the concept of inner nd outer class*/
class outer { int x=20; void displayouter() { inner obj1=new inner(); [Link](); } class inner { int y=30; void displayinner() { [Link]("x="+x); } } } class nestedmain { public static void main(String arg[]) { outer obj1=new outer(); [Link](); } }
Output
Pg|11
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
12./* program for callbyvalue*/
class call1 { void method(int x,int y) { x=10; x=20; } } class callvaluemain { public static void main(String arg[]) { int a=10; int b=20; [Link]("a="+a+"\n b="+b); call1 obji=new call1(); [Link](a,b); [Link]("a="+a+"\n b="+b); } }
output
Pg|12
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
13./* program for abstract class*/
abstract class a { int d; void get(int n) { d=n; } abstract void display(); } class b extends a { void display() { [Link]("d="+d); } } class Abs { public static void main(String args[]) { b obj=new b(); [Link](7); [Link](); }}
output
Pg|13
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
14./* wap to show the concept of constructor*/
class abc { int a,b; abc() { a=12; b=67; } void show() { [Link]("a="+a+"\nb="+b); } } class cons { public static void main(String args[]) { abc obj=new abc(); [Link](); } }
output
Pg|14
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
15./* program to show the concept of parametrized constructor*/
class paracon { int length,breath; paracon(int l,int b) { length=l; breath=b; } void show() { [Link]("Length="+length); [Link]("Breath="+breath); } } class paraconmain { public static void main(String args[]) { paracon ob1=new paracon(5,10); [Link](); }
output
Pg|15
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
16./* program for string concatenation*/
class simple { public static void main(String arg[]) { String s="sachin"; String s1=[Link]("tendulkar"); [Link](s1); } }
output
Pg|16
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
17. /* WAP to use substring()*/
class Simplesub { public static void main(String args[]) { String s="sachin tendulkar"; [Link]([Link](6)); [Link]([Link](0,6)); } }
output
Pg|17
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
18./*program of equals using string buffer class*/
class simple1 { public static void main(String arg[]) { String s1="jinia"; String s2="jinia"; String s3=new String("jinia"); String s4="deep"; [Link]([Link](s2)); [Link]([Link](s3)); [Link]([Link](s4)); } }
output
Pg|18
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
19./ * program to compare the strings*/
class compare { public static void main(String arg[]) { String s1="jinia"; String s2="jinia"; String s3="goyal"; [Link](s1==s2); [Link](s1==s3); } }
output
Pg|19
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
20./* program fpr trim,upper nd lower case()*/
class trim { public static void main(String arg[]) { String s="SACHIN"; [Link](s); [Link]([Link]()); [Link]([Link]()); [Link]([Link]()); } }
output
Pg|20
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
21./* WAP to measure the length of string by using length function*/
class Simplelength { public static void main(String args[]) { String s="SACHIN"; [Link]([Link]()); } }
output
Pg|21
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
22./* wap to show the concept of constructor*/
class abc { int a,b; abc() { a=12; b=67; } void show() { [Link]("a="+a+"\nb="+b); } } class cons { public static void main(String args[]) { abc obj=new abc(); [Link](); } }
output
Pg|22
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
23./* program to show the concept of parametrized constructor*/
class paracon { int length,breath; paracon(int l,int b) { length=l; breath=b; } void show() { [Link]("Length="+length); [Link]("Breath="+breath); } } class paraconmain { public static void main(String args[]) { paracon ob1=new paracon(5,10); [Link](); } }
Pg|23
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
Pg|24
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
24./*Wap to show the concept of super constructor*/
class rectangle { int dim1; int dim2; rectangle(int d1,int d2) { dim1=d1; dim2=d2; } void area() { [Link]("Area of Rectangle="+(dim1*dim2)); } } class trangle extends rectangle { trangle(int d1,int d2) { super(d1,d2); } void areat() { [Link]("Area of trangle="+((dim1*dim2)/2); } } class supercons1 { public static void main(String args[]) { trangle obj=new trangle(4,14); [Link](); [Link](); } }
Pg|25
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA [Link]-1277436
MCA-3rd sem Section-F
Output
Pg|26
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications