1./* write a program of print message*/
class MCA { public static void main(String args[]) { System.out.println("print"); } }
output
Pg|1
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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; System.out.println("addition is="+c); } }
output
Pg|2
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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; System.out.print("fib series is="); System.out.print("\t" +a); System.out.print("\t" +b); for(n=10;n>c;n--) { c=a+b;a=b;b=c; System.out.print("\t"+c); } } }
output
Pg|3
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-1277436
MCA-3rd sem Section-F
4./*program to show the use of static*/
class counter { static int count=0; counter() { count++; System.out.println(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 UNI.R.NO-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=arg.length; System.out.println("no of argument" +count); for(int i=0;i<count;i++) { System.out.println("arguments are"); System.out.println("arg["+i+"]="+arg[i]); } } }
output
Pg|5
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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=obj.fact(5); System.out.println("Factorial is="+f); } }
Output
Pg|6
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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(); obj1.setdata(10,20); area=obj1.length*obj1.breadth; System.out.println("area="+area); } }
output
Pg|7
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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++) { System.out.print(+ arr[i][j] + "\t"); } System.out.println(); } } }
output
Pg|8
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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++) System.out.print(c[i][j] + "\t"); System.out.println(); } } }
output
Pg|9
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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); System.out.println("obj1==obj2="+obj1.equals(obj2)); System.out.println("obj2==obj3="+obj2.equals(obj3)); System.out.println("obj1==obj3="+obj1.equals(obj3)); } }
output
Pg|10
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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(); obj1.displayinner(); } class inner { int y=30; void displayinner() { System.out.println("x="+x); } } } class nestedmain { public static void main(String arg[]) { outer obj1=new outer(); obj1.displayouter(); } }
Output
Pg|11
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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; System.out.println("a="+a+"\n b="+b); call1 obji=new call1(); obji.method(a,b); System.out.println("a="+a+"\n b="+b); } }
output
Pg|12
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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() { System.out.println("d="+d); } } class Abs { public static void main(String args[]) { b obj=new b(); obj.get(7); obj.display(); }}
output
Pg|13
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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() { System.out.println("a="+a+"\nb="+b); } } class cons { public static void main(String args[]) { abc obj=new abc(); obj.show(); } }
output
Pg|14
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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() { System.out.println("Length="+length); System.out.println("Breath="+breath); } } class paraconmain { public static void main(String args[]) { paracon ob1=new paracon(5,10); ob1.show(); }
}
output
Pg|15
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-1277436
MCA-3rd sem Section-F
16./* program for string concatenation*/
class simple { public static void main(String arg[]) { String s="sachin"; String s1=s.concat("tendulkar"); System.out.println(s1); } }
output
Pg|16
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-1277436
MCA-3rd sem Section-F
17. /* WAP to use substring()*/
class Simplesub { public static void main(String args[]) { String s="sachin tendulkar"; System.out.println(s.substring(6)); System.out.println(s.substring(0,6)); } }
output
Pg|17
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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"; System.out.println(s1.equals(s2)); System.out.println(s1.equals(s3)); System.out.println(s1.equals(s4)); } }
output
Pg|18
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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"; System.out.println(s1==s2); System.out.println(s1==s3); } }
output
Pg|19
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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"; System.out.println(s); System.out.println(s.trim()); System.out.println(s.toLowerCase()); System.out.println(s.toUpperCase()); } }
output
Pg|20
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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"; System.out.println(s.length()); } }
output
Pg|21
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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() { System.out.println("a="+a+"\nb="+b); } } class cons { public static void main(String args[]) { abc obj=new abc(); obj.show(); } }
output
Pg|22
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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() { System.out.println("Length="+length); System.out.println("Breath="+breath); } } class paraconmain { public static void main(String args[]) { paracon ob1=new paracon(5,10); ob1.show(); } }
Pg|23
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-1277436
MCA-3rd sem Section-F
Pg|24
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-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() { System.out.println("Area of Rectangle="+(dim1*dim2)); } } class trangle extends rectangle { trangle(int d1,int d2) { super(d1,d2); } void areat() { System.out.println("Area of trangle="+((dim1*dim2)/2); } } class supercons1 { public static void main(String args[]) { trangle obj=new trangle(4,14); obj.area(); obj.areat(); } }
Pg|25
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications
JINIA UNI.R.NO-1277436
MCA-3rd sem Section-F
Output
Pg|26
Chandigarh Group of Colleges,Landran(Mohali) Department of Computer Applications