/*

AIM:Write a program to calculate the sum of the following series :
1)1+(1/2)+(1/3)+.....+(1/n)
2)1-(1/2)+(1/3)-.....+(1/n)
3)1+(1/2^2)+(1/3^3)+.....+(1/n^n)
4)1+(1/3!)+(1/5!)+.....+(1/(2n-1)!)

*/

import java.io.*;
class Series
{
public static void main(String args[]) throws IOException
{
int i;
float s=0.0f;
System.out.println("Enter the no.: ");

for(i=1;i<=n;i++)
{
s=s+(1.0f/i);
}
System.out.println("Sum of series1 is : "+s);
s=0;
int sign =1;
for(i=1;i<=n;i++)
{
if (i%2==0)
{
sign=sign*(-1);
}
else
{
}

sign=1;

s=s+sign*(1.0f/i);
}
System.out.println("Sum of series2 is : "+s);
s=0;
for(i=1;i<=n;i++)
{

s=s+(1.0f/(i*i));

}
System.out.println("Sum of series3 is : "+s);
s=0;
int j;
int fact =1;
for(i=1;i<=n;i++)
{
for(j=1;j<=((2*i)-1);j++)
{
fact=fact*j;
}
s=s+(1.0f/fact);
}
System.out.println("Sum of series4 is : "+s);
}
}
/*

OUTPUT:

Enter the no.: 2
Sum of series1 is : 1.5
Sum of series2 is : 0.5
Sum of series3 is : 1.25
Sum of series4 is : 1.1666666

*/

.................................................................................................................
/*

Aim: Write a program to find greatest of 3 numbers using command line arguments

Class: SE-IT
Batch: B3

Roll No.:

*/

import java.io.*;
class GreatestNumber
{
public static void main(String args[])
{
int a,b,c;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
if (a>b)
{
if (a>c)
{
System.out.println("The greatest number is "+a);
}
else
{
System.out.println("The greatest number is "+c);
}
}
else
{
if (b>c)
{
System.out.println("The greatest number is "+b);
}
else
{
System.out.println("The greatest number is "+c);
}
}

... System.........in)).................. */ ...................... System......*.... } } /* OUTPUT : Enter a double value : 3...............*........... System..println("Smaller Value is : "+Math.out.....println("Greater Value is : "+Math. /* AIM : WAP on Calculator using switch case & operators import java...8 Smaller Value is : 3.....print("Enter a double value : ")......out..floor(d)).readLine())........... c) Largest Integer not greater than the number........ double d = Double..println("Value is : "+d)......... /* Aim-Write a program that will read a double type value from the keyboard and print the following output :a) Small Integer not less than the number..io.......................out.........0 Value is : 3....out.... System................... */ import java..........parseDouble(br...} } /* Output: java GreatestNumer 1 2 3 The greatest number is 3 java GreatestNumer 1 3 2 The greatest number is 3 java GreatestNumer 3 1 3 The greatest number is 3 */ .................... b) Given Number.0 */ ....................8 Greater Value is : 4..io.... class Exp3 {public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System..ceil(d))................

case '-': c=a-b.Addition "). double c. break.out. System.println("Numbers are "+a+" and "+b). char d.println(" Difference is "+c). DataInputStream in = new DataInputStream(System.out.println(" *.class Calculator { public static void main(String args[]) throws IOException { int a. case '/': . break. switch (d) { case '+': c=a+b.readLine()).out. a = Integer.parseInt(in.read(). d=(char)System. System.Subtract ").in.println(" Sum is "+c).out. System.println(" -. System. System.out.println(" +. b = Integer.out.println("Enter the second number: "). case '*': c=a*b.readLine()).b.in). System.println(" Enter the choice you want ").println("Enter the first number: "). System.out.out.Multiply "). System.parseInt(in. System.out.out. break.Divide "). System.println(" Product is "+c). System.println(" /.out.

5 */ -------------------------------------------------------------------------------------/*AIM : To display the following pattern : * *** ***** ***  */ import java.io. default : System.Multiply /.out. System.c=(double)a/b.print("Enter the No.n.Divide Enter the choice you want / Remainder is 0.println(" Entered wrong choice "). int i. break.j. .out.out. class Pattern1 {public static void main(String [] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System. of stars in middle line : ").in)).println(" Remainder is "+c).Addition -.*.Subtract *. System. } } } /* Output Enter the first number: 5 Enter the second number: 10 Numbers are 5 and 10 +.

i<=n.print(" ").i++) { for(j=i-1. for(j=2*i-1.out.println().out.j--) System.print(" ").out.println().j>0.out.i<=n. System.n=Integer.out. } for(i=2.out.j--) System.j>0.j>0. System.readLine()).j>0.parseInt(br.print("*"). for(i=1. for(j=2*(n-i)+1.j--) System.i++) { for(j=n-i. } } } /* OUTPUT : Enter the No. n=n/2+1. of stars in middle line : 5 * *** ***** ***  */ ------------------------------------------------------------------------------------/* AIM : To print following pattern : A ABA ABCBA ABCDCBA */ .print("*").j--) System.

*.in. if((c>='a') && (c<='z')) System. class CharCheck { public static void main(String args[]) throws IOException { char c.i++) { for(j=n-1. for(k=65.class Pattern2 {public static void main(String args[]) { int i.print(" "). System. for(i=0.i<n. System. numeric or symbolic.k++) System. c=(char)System.out.out.parseInt(args[0]).j>=i. .print((char)(k)). } } } /* OUTPUT : D:\OOPM>java Pattern2 4 A ABA ABCBA ABCDCBA */ ------------------------------------------------------------/* AIM : WAP To check whether the entered character is lowercase or uppercase.k<(65+i).io.j.k>=65.out. int n=Integer.read().out.j--) System.println(). for(.println("Enter the character:").println("it is lowercase").k--) System. */ import java.out.out.k.print((char)(k)).

print("Factorial of "+n+" = "+fact).print("Enter n = ").out. System. int n = Integer.out. } public static int factorial(int n) { if(n==0||n==1) */ .println("it is uppercase").out. System. import java. else if((c>='0') && (c<='9')) System. int fact = factorial(n).else if((c>='A') && (c<='Z')) System.println("it is a symbol").parseInt(din.io.out. } } /* OUTPUT Enter the character: a it is lowercase Enter the character: A it is uppercase Enter the character: 9 it is numeric Enter the character: / it is a symbol */ ---------------------------------------------------------------------------/* AIM : To find factorial of given number using recursion.out.in). else System. class Factorial {public static void main(String args[]) throws IOException { DataInputStream din = new DataInputStream(System.*.readLine()).println("it is numeric").

parseInt(buf.print("Enter array size : "). class BubbleSort {public static void main(String args[]) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.i<n. int a[] = new int[n].parseInt(buf.i++) a[i] = Integer. System.out.out. for(int i=0.out. for(int i=0.in)).*. a[j] = a[j+1]. a[j+1] = temp.out. } } /* OUTPUT : Enter n = 4 Factorial of 4 = 24 */ --------------------------------------------------------------------------------------/* AIM : WAP to sort integers using bubble sort algorithm. } } } System.print(" "+a[i]).j<n-1.io.i<n. int n = Integer.j++) { if(a[j]>a[j+1]) { int temp = a[j].println("Enter array elements : ").println("\nSorted array elements : ").i++) System.return 1.i++) { for(int j=0. .i<n. for(int i=0. else return n*factorial(n-1).readLine()).readLine()). */ import java. System.

boolean flag=false.out.out. for(i=0. for(int i=0.parseInt(obj. int a[] = new int[n].readLine()). */ import java.parseInt(obj.print("Enter element to be searched : ").i<n. System.} } /* OUTPUT : Enter array size : 5 Enter array elements : 34 21 54 23 6 Sorted array elements : 6 21 23 34 54 */ ---------------------------------------------------------------------------/*AIM : To implement sequential search algorithm. class LinearSearch { public static void main(String args[])throws IOException { BufferedReader obj=new BufferedReader(new InputStreamReader(System.readLine()).out. System.readLine()). . System.println("Enter array elements : ").i<n. int ele=Integer.*.i++) { if (a[i]==ele) { flag=true.print("Enter no.in)). int i=0.parseInt(obj. int n = Integer.of elements : ").i++) a[i]=Integer.io.

} if(flag) System. follows :- . */ import java. } else flag=false.println("Element Found at index : "+i). Subject1 Subject2 Subject3 Write a program to read the data and determine: (i)Total marks obtained by each student (ii)The student who obtained the highest total marks.of elements : 4 Enter array elements : 23 14 5 32 Enter element to be searched : 8 Element not found Enter no.of elements : 4 Enter array elements : 43 13 4 32 Enter element to be searched : 13 Element Found at index : 1 */ -------------------------------------------------------------------/*AIM : The annual examination results of 5 students are tabulated as RollNo.println("Element not found").out.*.break. else System.out. } } /* OUTPUT : Enter no.io.

} student[i][4]=total_marks. for(i=0. for(j=1.j<5. : ").j++) { System.m=0. int i.class StudentRecord { public static void main(String args[]) throws IOException { DataInputStream ob=new DataInputStream(System.out.print("Enter the no.out.in).readLine()). student[i][j]=Integer.j<=3.j++) { System.i++) { System. for(i=0.println().print(student[i][j]+"\t").readLine()).out.print("Enter marks of sub"+j+" = ").parseInt(ob.out. System.out.max=0. System.println("Roll\tSub1\tSub2\tSub3\tTotal").readLine()).parseInt(ob.total_marks. } System.parseInt(ob.out. int student[][]=new int[n][5].out. } . total_marks=total_marks+student[i][j].i++) { for(j=0. int n = Integer. total_marks=0. student[i][0]=Integer.i<n.println("\nThe marks of students are : ").print("\nEnter the roll no. of students : "). } System.j.i<n.

i++) { if (student[i][4]<student[i+1][4]) { max=student[i+1][4]. : 1 Enter marks of sub1 = 23 Enter marks of sub2 = 22 Enter marks of sub3 = 12 Enter the roll no.out.i<n-1. } } System.println("\nHighest total marks are "+max+" obtained by Roll No. : 3 Enter marks of sub1 = 14 Enter marks of sub2 = 23 Enter marks of sub3 = 21 The marks of students are : Roll Sub1 Sub2 Sub3 Total 1 23 22 12 57 2 32 19 32 83 3 14 23 21 58 Highest total marks are 83 obtained by Roll No. of students : 3 Enter the roll no. 2 */ ---------------------------------------------------------------------------------------/*AIM : Write an object oriented program to arrange names of students in descending order . } } /* OUTPUT : Enter the no. "+m). m = student[i+1][0]. : 2 Enter marks of sub1 = 32 Enter marks of sub2 = 19 Enter marks of sub3 = 32 Enter the roll no.for(i=0.

chem. Physics and Chemistry. math=Double.println("Enter marks of phy.out. class Marks { int std_id. double math. chem=Double.in).parseDouble(ob. name=ob.readLine()).readLine(). void getData()throws IOException { DataInputStream ob=new DataInputStream(System.readLine()).readLine()). } void displayData() { System.phy.*/ import java.parseInt(ob.readLine()).total.j. Id no and marks obtained in Mathematics.parseDouble(ob. Use the concept of array of objects. phy=Double.println(std_id+"\t"+name+"\t"+total). Input data consists of student details such as name. chem & maths : "). } } class Student { public static void main(String args[])throws IOException { int i.of their total marks. .*. } void processData() { total=math+chem+phy. std_id=Integer. System.io.parseDouble(ob.out.println("Enter the id & name of student : "). System. String name.out.

out.D.println("Details of the students are : \n"). } } } /*OUTPUT Enter the no. s[i].j<n-1.i<n. System. System.getData(). s[j]=s[j+1].in).processData().i<n. s[j+1]=temp.parseInt(ob. for(i=0. int n = Integer. for(i=0.i++) { s[i]= new Marks().total) { temp=s[j].total<s[j+1].out. for(i=0.out.i++) { s[i].displayData().readLine()).j++) { if (s[j]. } } } System. of students : 3 Enter the id & name of student : . of students : ").\tName\tTotal").println("I.print("Enter the no.DataInputStream ob=new DataInputStream(System.i<n. } Marks temp=new Marks(). s[i]. Marks s[]=new Marks[n].i++) { for( j=0.

io. chem & maths : 23 23 23 Enter the id & name of student : 2 xyz Enter marks of phy. . DataInputStream ds=new DataInputStream(System.0 */ -----------------------------------------------------------------------------/*AIM : Write a program to check whether a given string is Palindrome or not. chem & maths : 31 21 32 Details of the students are : I. Name Total 3 lmn 84. chem & maths : 12 21 13 Enter the id & name of student : 3 lmn Enter marks of phy.D.0 1 abc 69.1 abc Enter marks of phy.in). */ import java.0 2 xyz 46.*. class Palindrome { public static void main(String args[]) throws IOException { String str.

println("Enter a String: "). .i++. for(i=0. boolean flag=true.out.len = str. else { flag=false.out. } } /*OUTPUT Enter a String: MALAYALAM String : MALAYALAM String is palindrome */ ------------------------------------------------------------------------/*AIM : WAP to capitalize the first character of each word from a given sentence. } } if(flag==true) System.println("\nString : "+str).j.out. int i. else System.System.io.in). break.length().charAt(i)==str.charAt(j)) flag=true. (Example: all the best All The Best)*/ import java.readLine(). DataInputStream in = new DataInputStream(System.println("String is palindrome").*.j--) { if(str. System. class CapitalFirstChar {public static void main(String args[]) throws IOException { String s=null. str=ds.out.println("String is not palindrome").i<=len/2.j=len-1.

io.substring(i+2). System.toUpperCase(s.i++) { if(Character.charAt(i))) s++. String str = dis.isSpace(str. else if(Character.charAt(0)) + s.isUpperCase(str.readLine().substring(1).lowercase letters.i<str.println("Enter a sentence : ").charAt(i))) l++.print("Enter string : "). s = in.out.s=0.charAt(i+1)) + s.out. int l=0.charAt(i))) n++.i<s.substring(0. } } /* OUTPUT : Enter a sentence all the best All The Best */ ---------------------------------------------------------------------/*AIM : WAP to count no. .n=0.readLine(). for(int i=0. s =Character.in).isDigit(str. of uppercase .toUpperCase(s.println(s).i++) { if(s.*/ import java. of digits and blank spaces in a given string. } System. else if(Character.System.u=0.charAt(i) == ' ') s=s. & no.length(). class StringCheck {public static void main(String args[]) throws IOException { DataInputStream dis = new DataInputStream(System. else if(Character.*.isLowerCase(str.length().i+1) + Character.out. for(int i =0.charAt(i))) u++.

class Vector_Demo {public static void main(String args[]) { Vector v = new Vector(4.println("Final capacity is: " + v.out.println(e. } Enumeration e = v.println("\nElements in vector:").capacity()).println("Intial capacity is: " + v.util.elements().. } System. while(e. */ import java.*. System. System.capacity()).nextElement()+ " ").hasMoreElements()) { System. } } /*OUTPUT : Enter string : HI.out.out.addElement(new String(args[i])).size()).print("\nUpper case = "+u+"\nLower case = "+l+"\nDigits = "+n+"\nBlank Spaces = "+s). for(int i =0.2).out.size()).out.length. 123 how are you? Upper case = 2 Lower case = 9 Digits = 3 Blank Spaces = 4 */ ----------------------------------------------------------------------------------/* AIM : Write a program to accept student names from the command line & store them in a vector.} System. System. System.println("Final size is: " +v. i++) { v.out. } } /* OUTPUT D:\OOPM>java Vector_Demo deep ramesh komal raj neel . i<args.println("Intial size is: " +v.out.

in)). else throw new NumberRangeException().out.print("Enter month number : ").readLine()).io. } } class My_Exception { public static void main (String args []) throws IOException { try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System. class NumberRangeException extends Exception { String msg. Throw an exception if improper month number is entered. */ import java. int x = Integer. NumberRangeException() { msg = new String("Exception : Enter a number between 1 and 12").parseInt(obj. System. .out.println(x+" is a valid month number").*. Make your own exception class to handle this exception. if (x >= 1 && x <=12) System.Intial size is: 0 Intial capacity is: 4 Elements in vector: deep ramesh komal raj neel Final size is: 5 Final capacity is: 6 */ ---------------------------------------------------------------------------------------------/*AIM : Write a Program to accept and display the month number.

msg).println (e. Consider a class network given. Write a program to display 'Admin' object.*/ class Person //super class { protected String name. protected int code.out.println("Name of person is: "+name+"\nCode is: "+code). The class 'Admin' derives information from the class 'Account' which in turn derives information from the 'Person' class. int c) { name=n. } } class Account extends Person { //intermediate super class . code=c. Person(String n.out.} catch (NumberRangeException e) { System. } } } /*OUTPUT : D:\OOP>java My_Exception Enter month number : 33 Exception : Enter a number between 1 and 12 D:\OOP>java My_Exception Enter month number : 6 6 is a valid month number */ --------------------------------------------------------------------------------/*AIM : 1. } public void display() { System.

protected int pay.out.c.display().5).p).c).int c. } public void display() { super.display(). Account(String n. } public void display() { super. } } class CompanyRecords { public static void main( String args[]) { Admin m=new Admin("ABC".1001.out.display(). System.println("Salary : "+pay). int p) { super(n. int c. } } class Admin extends Account //sub class { protected int exp. pay=p.10000. System.println("Experience : "+exp). Admin(String n.int e) { super(n. exp=e.int p. } } . m.

0/3. } class Sphere extends Calculate { double volume() { return((4. . abstract class Calculate { protected double r.in). } } class Hemisphere extends Calculate { double volume() { return((2. abstract double volume().Scanner./* OUTPUT : Name of person is: ABC Code is: 1001 Salary : 10000 Experience : 5 */ ------------------------------------------------------------------/*AIM : Write a program to display volume of sphere and hemisphere. } } class Volume { public static void main(String args[]) { Scanner sc = new Scanner(System.0) * pi * r * r * r). Make use of abstract class. protected double pi = 3. */ import java.0/3.14.0) * pi * r* r * r).util.

r = sc.938239999999997 */ ---------------------------------------------------------------------------------------------/*AIM :Interface Matrix { final static int M=5.util.out. System. System.r= sc. . //Read a Matrix void displayMatrix(). h. //Display a Matrix void addMatrix().2 Volume of sphere is : 137.18869333333336 Enter the radius of hemisphere : 2. //Matrix indices void readMatrix(). s. public void addMatrix().volume()).print("\nEnter the radius of hemisphere : ").nextDouble(). } } /* OUTPUT : Enter the radius of sphere : 3.4 Volume of hemisphere is : 28.out. N=5. public void displayMatrix(). interface Matrix { final static int M=5.print("Enter the radius of sphere : ").volume()).Scanner. public void readMatrix(). // Add two Matrix void multMatrix(). Hemisphere h = new Hemisphere(). System.out.Sphere s = new Sphere(). System. */ import java. //Multiply two matrix void transposeMatrix() //Transpose of Matrix } Implement the above interface using a suitable JAVA class program and also develop the main program. N=5.println("Volume of sphere is : " +s.out.nextDouble().println("Volume of hemisphere is : " +h.

} } System.i++) { for(int j=0. int y[][]=new int[3][3].j++) { x[i][j]=sc.i<3. } } } public void displayMatrix() { System.println("Enter the elements for Matrix 2 : ").public void multMatrix().j++) { y[i][j]=sc. for(int i=0. System. int z[][]=new int[3][3]. public void transposeMatrix(). for(int i=0.println("Displaying Matrix 1 : "). public void readMatrix() { Scanner sc = new Scanner(System. for(int i=0.in).j++) .j<3.i<3.out.j<3.out.i++) { for(int j=0.nextInt(). } class MatrixOperations implements Matrix { int x[][]=new int[3][3].out.j<3.nextInt().println("Enter the elements for Matrix 1 : ").i<3.i++) { for(int j=0.

for(int i=0.out.i<3.i++) { for(int j=0.println().print(y[i][j]+ " ").println(). for(int i=0.out.i++) { for(int j=0.j<3.out.println("Displaying Matrix 2 : ").out.{ System.i++) { for(int j=0.out.j++) { z[i][j]=x[i][j]+y[i][j].print(z[i][j]+ " ").j++) . } System.println("Displaying Addition of Matrices : "). } System.out. } } public void addMatrix() { System. } System.j++) { System.i<3.print(x[i][j]+ " ").out.j<3.println().println("Displaying Multiplication of Matrices :"). } System.j<3. } } public void multMatrix() { System. System.out.i<3.out. for(int i=0.

} } } class MatrixDemoInterface { public static void main(String args[]) { MatrixOperations a =new MatrixOperations().out. } } public void transposeMatrix() { System. a.i++) { for(int j=0.j<3.println("Displaying Transpose of Matrix 1 : ").readMatrix(). } System. a. } System.j++) { System. } . a.displayMatrix().out. } System.multMatrix(). a. for(int i=0.println().{ z[i][j]=0.print(x[j][i]+ " ").out.k<3.k++) { z[i][j]+=x[i][k]*y[k][j].println().out.i<3.transposeMatrix().addMatrix(). a. for(int k=0.print(z[i][j]+ " ").out.

} /*OUTPUT Enter the elements for Matrix 1 : 1 2 1 3 3 2 2 1 5 Enter the elements for Matrix 2 : 3 2 4 1 2 6 2 1 1 Displaying Matrix 1 : 1 2 1 3 3 2 2 1 5 Displaying Matrix 2 : 3 2 4 1 2 6 2 1 1 Displaying Transpose of Matrix 1 : 1 3 2 2 3 1 1 2 5 .

100.drawOval(20.30). } } OUTPUT : D: \OOP>javac FaceExample.50.70. public class FaceExample extends Applet { public void paint(Graphics g) { g.awt.drawOval(110.drawLine(100. g.30). g.drawLine(70.html <html> <applet CODE = "FaceExample.130. import java.100).java import java.100.*.80).class" WIDTH=200 HEIGHT=150> </applet> </html> // FaceExample.Displaying Addition of Matrices : 4 4 5 4 5 8 4 2 6 Displaying Multiplication of Matrices : 7 7 17 16 14 32 17 11 19 */ -----------------------------------------------------------------------------/* AIM : Write an applet to display the following : */ // face.20.20.applet.70.java . g.*.

h.println("Hello !!! This is inside package : world ").java ( Inside folder named “world” ) package world.java import world. */ class A extends Thread { public void run() . public class Hello { public void display() { System.html ---------------------------------------------------------------------------------------/*AIM : Write a program to design & import a package. */ // Hello.out.D:\OOP>appletviewer face. class HelloDemo { public static void main(String args[]) { Hello h=new Hello(). } } /*OUTPUT : Hello !!! This is inside package : world */ -----------------------------------------------------------------------------/*AIM : Write a program to print 1A2B3C4D5E6F7G8H9I10J using two child threads. } } // HelloDemo.display().*.

} catch(Exception e){} } } } class Multithreading { public static void main(String args[]) { A a =new A().print((char)(i+64)). } } /*OUTPUT : .print(i). } catch(Exception e){} } } } class B implements Runnable { public void run() { for(int i=1.sleep(500). a. B b =new B(). try{ Thread. try{ Thread. Thread t=new Thread(b).out.i<=10.start().i++) { System.sleep(550).i++) { System. t.start().{ for(int i=1.i<=10.out.

1A2B3C4D5E6F7G8H9I10J */ .