You are on page 1of 29

PROGRAM:

import java.io.*; class sum { Public static void main(String args[]) { float a,b,res_sum; a=10; b=25; res_sum=a+b; System.out.println( sum = +res_sum); } }

RESULT:

PROGRAM:

import java.io.*; class area { public static void main(String args[]) { float len,br,ar; len=100; br=75; ar=len*br; System.out.println( Area = +ar); } }

RESULT:

PROGRAM:

import java.io.*; class matrixadd { public static void main(String args[]) { int a[][]={{1,2},{1,2}},b[][]={{1,1},{1,1}},c[][]={{0,0},{0,0}},i,j; for(i=0;i<2;i++) { for(j=0;j<2;j++) { c[i][j]=a[i][j]+b[i][j]; } } for(i=0;i<2;i++) { for(j=0;j<2;j++) { System.out.print( }System.out.println( ); } } } +c[i][j]);

RESULT:

PROGRAM:

import java.io.*; class matrixmul { public static void main(String args[]) { int a[][]={{1,1},{1,1}},b[][]={{1,1},{1,1}},c[][]={{0,0},{0,0}},I,j,k; for(i=0;i<2;i++) { for(j=0;j<2;j++) { for(k=0;k<2;k++) { } } } for(i=0;i<2;i++) { for(j=0;j<2;j++) { System.out.print( +c[i][j]); c[i][j]=c[i][j]+a[i][k]*b[k][j];

}System.out.println( ); } } }

RESULT:

PROGRAM: import java.io.*; class circle { double rad,ar; circle( ) { rad=0; }

circle(double r) { rad=r; }

void cal( ) { } void print( ) { } } class area { public static void main(String args[]) { circle c1=new circle( ); circle c2=new circle(5); c1.cal; c2.cal; c1.print( ); c2.print( ); } } System.out.println( Area of circle with radius +rad+ = +ar); ar=3.14*rad*rad;

RESULT:

PROGRAM:

class fact { public static void main(String args[]) { int n,fact,i; System.out.println( enter any number: ); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); n=Integer.parseInt(br.readLine());

fact=1; for(i=n;i>=1;i--) { fact=fact*i; } System.out.println( Factorial of +n+ = +fact); } }

RESULT:

PROGRAM:

import java.io.*; class office { int id,age,salary; void read( ) { id=0; age=0; salary=0; } void read(int i,int a,int s) { id=i; age=a; salary=s; } void read(int i,int s) { id=i; age=25; salary=s; } void print( ) { System.out.println( ID NO: +id); System.out.println( AGE : +age); System.out.println( SALARY : +salary); } }

class disp { public static void main(String args[]) { office a=new office; office b=new office; office c=new office; a.read(); b.read(100,22,50000); c.read(110,55000); a.print(); b.print(); c.print(); } }

RESULT:

PROGRAM:

import java.io.*; interface college { final static int dir=1; void office(); void student(); } interface staff { } class student { int stu; student(int n); { } class engg extends student implements college,staff { int teach,dept,nonteach; engg(int a,int b,int c,int d) { super(a); teach=b; dept=c; nonteach=d; } public void office() { System.out.println( OFFICE ); System.out.println( number of non teaching staffs: +nonteach); } stu=n; } void department();

public void student() { System.out.println( STUDENT ); System.out.println( number of students: +stu); } public void department() { System.out.println( DEPARTMENT ); System.out.println( number of teaching staffs: +teach); System.out.println( number of directors: +dir); } } class detail { public static void main(String args[]) { engg e=new engg(1000,100,12,50); e.office(); e.student(); e.department(); } }

RESULT:

PROGRAM:

import java.io.*; class box { int length,width,height; public box() { length=10; width=20; height=30; } void volume() { double vol; vol=length*width*height; } } class boxweight extends box { int weight; boxweight() { weight=40; }

void show() { System.out.println( length: +length+ width: +width+ height: +height); System.out.println( volume: +vol); } }

class boxcolour extends boxweight { String c[]={ red }; void disp() { System.out.println( weight: +weight); for(int i=0;i<2;i++) { System.out.print( colour: +colour[i]); } } } class detail { public static void main(String args[]) { box b1=new box(); boxweight b2=new boxweight(); boxcolour b3=new boxcolour(); b1.volume(); b2.show(); b3.disp(); } }

RESULT:

PROGRAM:

import java.io.*;

class box { double width; double length; double depth; box(double w,double l,double d) { width=w; length=l; depth=d; } box(double len) { } double volume() { } } class boxweight extends box { double weight; boxweight(double w,double l,double d,double m) { super(w,l,d); weight=m; } } return(width*length*depth); width=length=depth=len;

class boxvolume { public static void main(String args[]) { boxweight b1=new boxweight(5,15,10,20); boxweight b2=new boxweight(8,10); double vol=b1.volume(); System.out.println( volume of cuboid= +vol); System.out.println( weight= +b1.weight); double vol=b2.volume(); System.out.println( volume of cube= +vol); System.out.println( weight= +b2.weight); } }

RESULT:

PROGRAM:

import java.io.*; import java.lang.*;

class stringtest { public static void main(String args[]) { String s1,s2,s3,s4; s1= SRM ; s2= srm ; s3= srm ; s4= UNIVERSITY ; System.out.println( length of 1st string= +s1.length()); String s=s1+s4; System.out.println( string 1 + string 4= +s); char ch; ch=s1.charAt(2); System.out.println( character at index position 2 of +s1+ : +ch); System.out.println(s1+ equals +s2+ = +s1.equals(s2)); System.out.println(s3+ equals +s2+ = +s3.equals(s2)); System.out.println(s1+ equalsIgnorecase +s2+ = +s1.equalsIgnorecase(s2)); System.out.println(s1+ compared to +s2+ = +s1.compareTo(s2)); System.out.println( index of I in +s4+ after S = +s4.indexOf( i , s )); System.out.println( substring of +s4+ = +s4.substring(0,4)); System.out.println( concatenation(string 1 & 4)= +s1.concat(s4)); System.out.println( change +s2+ to uppercase= +s2.toUpperCase()); System.out.println( replace m in +s3+ with n = +s3.replace( m , n )); String Buffer s5=new String Buffer( contraption );

System.out.println( buffer= +s5); System.out.println( length = +s5.length()+ capacity = +s5.capacity()); s6=s5.append( ! ).toString(); System.out.println( append ! to contraption = +s6); System.out.println( insertion = +s5.insert(2, compass )); System.out.println( reversing = +s5.reverse()); } }

RESULT:

PROGRAM:

import java.io.*; import java.lang.EXCEPTION;

class newexcep extends EXCEPTION { newexcep(String msg) { } } class excep { public static void main(String args[]) { float a,b; double c=0.0; System.out.println( enter x: ); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); a=Integer.parseInt(br.readLine()); System.out.println( enter y: ); BufferedReader z=new BufferedReader(new InputStreamReader(System.in)); b=Integer.parseInt(z.readLine()); try { c=a/b; if(c<0.05) { } catch(newexcep e) { System.out.println( caught new exception ); System.out.println(e.getMessage()); throw new newexcep( x is very small ); Super(msg);

} finally { } } } System.out.println( X/Y = +c);

PROGRAM:

import java.io.* import java.lang.*;

class newthread1 extends Thread { public void run() { for(int i=1;i<5;i++) { System.out.println( from new thread1: i = +i);

}System.out.println( exit from new thread1 ); } } class newthread2 extends Thread { public void run() { for(int j=1;j<5;j++) { System.out.println( from new thread2: j = +j);

} System.out.println( exit from new thread2 ); } } class newthread3 extends Thread { public void run() { for(int k=1;k<5;k++) { System.out.println( from new thread3: k = ki);

} System.out.println( exit from new thread3 ); } }

class threadtest { public static void main(String args[]) { newthread1 a=new newthread1(); newthread2 b=new newthread2(); newthread3 c=new newthread3(); a.start(); b.start(); c.start(); } }

RESULT:

PROGRAM: /*package creation*/ Package pack; public class newpackage { int regno; String name; public newpackage(int r,String n) { regno=r; name=n; } public void print() { System.out.println( registration no.: +regno); System.out.println( name : +name); } } /*main*/ import java.io.*; import pack.*; class packagetest { public static void main(String args[]) { newpackage p=new newpackage(1030910133, Mridul ); p.print(); } }

RESULT:

PROGRAM:

import java.io.*; class first { int a,b; first(int x,int y) { a=x; b=y; } void print() { } } class second extends first { int c; second(int x,int y,int z) { Super(x,y); c=z; } void print(String msg) { } void print() { } } System.out.println( c = +c); System.out.println(msg); System.out.println( a = +a+ b= +b);

class override { public static void main(String args[]) { second s=new second(10,20,30); s.print(); } }

RESULT:

PROGRAM:

import java.io.*; class box { double width,length,depth,weight; String colour; public box() { width=20; length=30; depth=10; weight=100; colour= red ; } void show() { System.out.println( width= +width+ length= +length+ depth= +depth); System.out.println( volume= +(width*length*depth)); } } class boxweight extends box { boxweight(double weight) { } void display() { } } System.out.println( weight= +weight); Super(weight);

class boxcolour extends box { boxcolour(String colour) { } void print() { } } class hierarchial { public static void main(String args[]) { boxweight b1=new boxweight(); boxcolour b2=new boxcolour(); b1.show(); b1.display(); b2.show(); b2.print(); } } System.out.println( colour = +colour); Super(colour);

RESULT:

PROGRAM:

import java.io.* class fibo { public static void main(String args[]) { int i,n,a,b,c; System.out.println( enter any number = ); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); n=Integer.parseInt(a.readLine()); a=0; b=1; System.out.println(a+ System.out.println(b+ for(i=0;i<n;i++) { c=a+b; a=b; b=c; System.out.println(c+ } } } ); ); );

RESULT:

PROGRAM:

import java.io.*; class perfect { public static void main(String args[]) { int i,j,sum; for(i=1;i<500;i++) { sum=0; for(j=1;j<1;j++) { if(i%j==0) { } } if(sum==i) { } } } } System.out.println( perfect number = +i); sum=sum+j;

RESULT:

PROGRAM:

import java.io.*; class sum { double r,i; void read() throws IOException { System.out.println( enter the real and imaginary number : ); BufferedReader rp=new BufferedReader(new InputStreamReader(System.in)); r=Integer.parseInt(rp.readLine()); BufferedReader ip=new BufferedReader(new InputStreamReader(System.in)); i=Integer.parseInt(ip.readLine()); } void add(sum c1,sum c2) { r=c1.r+c2.r; i=c1.i+c2.i;

System.out.println( complex number = +r+ + i +i); } } class complex { public static void main(String args[]) throws IOException { sum comp1=new sum(); sum comp2=new sum(); sum comp3=new sum(); comp1.read(); comp2.read(); comp3.add(comp1,comp2); } }

RESULT:

You might also like