*/
import java.io.*;
class Series
{
public static void main(String args[]) throws IOException
{
BufferedReader obj =new BufferedReader(new
InputStreamReader(System.in));
int i;
float s=0.0f;
System.out.println("Enter the no.: ");
int n=Integer.parseInt(obj.readLine());
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:
*/
.................................................................................................................
/*
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);
}
}
}
}
/*
*/
...................................................................................................................................
/* 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.
b) Given Number.
c) Largest Integer not greater than the number. */
import java.io.*;
class Exp3
{public static void main(String args[]) throws IOException
{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a double value : ");
double d = Double.parseDouble(br.readLine());
System.out.println("Smaller Value is : "+Math.floor(d));
System.out.println("Value is : "+d);
System.out.println("Greater Value is : "+Math.ceil(d));
}
}
/*
OUTPUT :
*/
.......................................................................................................................
/*
import java.io.*;
*/
class Calculator
{
public static void main(String args[]) throws IOException
{
int a,b;
double c;
char d;
DataInputStream in = new DataInputStream(System.in);
System.out.println("Enter the first number: ");
a = Integer.parseInt(in.readLine());
System.out.println("Enter the second number: ");
b = Integer.parseInt(in.readLine());
System.out.println("Numbers are "+a+" and "+b);
System.out.println(" +.Addition ");
System.out.println(" -.Subtract ");
System.out.println(" *.Multiply ");
System.out.println(" /.Divide ");
System.out.println(" Enter the choice you want ");
d=(char)System.in.read();
switch (d)
{
case '+':
c=a+b;
System.out.println(" Sum is "+c);
break;
case '-':
c=a-b;
System.out.println(" Difference is "+c);
break;
case '*':
c=a*b;
System.out.println(" Product is "+c);
break;
case '/':
c=(double)a/b;
System.out.println(" Remainder is "+c);
break;
default : System.out.println(" Entered wrong choice ");
}
}
}
/* Output
Enter the first number:
5
Enter the second number:
10
Numbers are 5 and 10
+.Addition
-.Subtract
*.Multiply
/.Divide
Enter the choice you want
/
Remainder is 0.5
*/
*/
import java.io.*;
class Pattern1
{public static void main(String [] args)throws IOException
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,j,n;
System.out.print("Enter the No. of stars in middle line : ");
n=Integer.parseInt(br.readLine());
n=n/2+1;
for(i=1;i<=n;i++)
{
for(j=n-i;j>0;j--)
System.out.print(" ");
for(j=2*i-1;j>0;j--)
System.out.print("*");
System.out.println();
}
for(i=2;i<=n;i++)
{
for(j=i-1;j>0;j--)
System.out.print(" ");
for(j=2*(n-i)+1;j>0;j--)
System.out.print("*");
System.out.println();
}
}
}
/*
OUTPUT :
*/
------------------------------------------------------------------------------------/*
*/
class Pattern2
{public static void main(String args[])
{ int i,j,k;
int n=Integer.parseInt(args[0]);
for(i=0;i<n;i++)
{
for(j=n-1;j>=i;j--)
System.out.print(" ");
for(k=65;k<(65+i);k++)
System.out.print((char)(k));
for(;k>=65;k--)
System.out.print((char)(k));
System.out.println();
}
}
}
/*
OUTPUT :
D:\OOPM>java Pattern2 4
A
ABA
ABCBA
ABCDCBA
*/
------------------------------------------------------------/* AIM : WAP To check whether the entered character is lowercase or uppercase, numeric or
symbolic.
*/
import java.io.*;
class CharCheck
{
public static void main(String args[]) throws IOException
{
char c;
System.out.println("Enter the character:");
c=(char)System.in.read();
if((c>='a') && (c<='z'))
System.out.println("it is lowercase");
OUTPUT
*/
---------------------------------------------------------------------------/*
import java.io.*;
class Factorial
{public static void main(String args[]) throws IOException
{ DataInputStream din = new DataInputStream(System.in);
System.out.print("Enter n = ");
int n = Integer.parseInt(din.readLine());
int fact = factorial(n);
System.out.print("Factorial of "+n+" = "+fact);
}
public static int factorial(int n)
{ if(n==0||n==1)
*/
return 1;
else
return n*factorial(n-1);
}
}
/*
OUTPUT :
Enter n = 4
Factorial of 4 = 24
*/
--------------------------------------------------------------------------------------/*
*/
import java.io.*;
class BubbleSort
{public static void main(String args[]) throws IOException
{ BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter array size : ");
int n = Integer.parseInt(buf.readLine());
int a[] = new int[n];
System.out.println("Enter array elements : ");
for(int i=0;i<n;i++)
a[i] = Integer.parseInt(buf.readLine());
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
}
}
}
System.out.println("\nSorted array elements : ");
for(int i=0;i<n;i++)
System.out.print(" "+a[i]);
}
}
/*
OUTPUT :
*/
import java.io.*;
class LinearSearch
{
public static void main(String args[])throws IOException
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter no.of elements : ");
int n = Integer.parseInt(obj.readLine());
int a[] = new int[n];
System.out.println("Enter array elements : ");
for(int i=0;i<n;i++)
a[i]=Integer.parseInt(obj.readLine());
System.out.print("Enter element to be searched : ");
int ele=Integer.parseInt(obj.readLine());
int i=0;
boolean flag=false;
for(i=0;i<n;i++)
{
if (a[i]==ele)
{
flag=true;
break;
}
else
flag=false;
}
if(flag)
System.out.println("Element Found at index : "+i);
else
}
}
/*
OUTPUT :
*/
Subject1
Subject2
Subject3
follows :-
class StudentRecord
{
public static void main(String args[]) throws IOException
{
DataInputStream ob=new DataInputStream(System.in);
System.out.print("Enter the no. of students : ");
int n = Integer.parseInt(ob.readLine());
int student[][]=new int[n][5];
int i,j,total_marks,max=0,m=0;
for(i=0;i<n;i++)
{
System.out.print("\nEnter the roll no. : ");
student[i][0]=Integer.parseInt(ob.readLine());
total_marks=0;
for(j=1;j<=3;j++)
{
System.out.print("Enter marks of sub"+j+" = ");
student[i][j]=Integer.parseInt(ob.readLine());
total_marks=total_marks+student[i][j];
}
student[i][4]=total_marks;
}
System.out.println("\nThe marks of students are : ");
System.out.println("Roll\tSub1\tSub2\tSub3\tTotal");
for(i=0;i<n;i++)
{
for(j=0;j<5;j++)
{
System.out.print(student[i][j]+"\t");
}
System.out.println();
}
for(i=0;i<n-1;i++)
{
if (student[i][4]<student[i+1][4])
{
max=student[i+1][4];
m = student[i+1][0];
}
}
System.out.println("\nHighest total marks are "+max+" obtained by Roll No. "+m);
}
}
/*
OUTPUT :
Sub1
Sub2
Sub3 Total
23
22
12
57
32
19
32
83
14
23
21
58
*/
---------------------------------------------------------------------------------------/*AIM : Write an object oriented program to arrange names of students in descending order
1
abc
Enter marks of phy, chem & maths :
23
23
23
Enter the id & name of student :
2
xyz
Enter marks of phy, chem & maths :
12
21
13
Enter the id & name of student :
3
lmn
Enter marks of phy, chem & maths :
31
21
32
Details of the students are :
I.D.
Name Total
lmn
84.0
abc
69.0
xyz
46.0
*/
*/
------------------------------------------------------------------------/*AIM : WAP to capitalize the first character of each word from a given sentence.
(Example: all the best All The Best)*/
import java.io.*;
class CapitalFirstChar
{public static void main(String args[]) throws IOException
{
String s=null;
DataInputStream in = new DataInputStream(System.in);
if(Character.isUpperCase(str.charAt(i)))
u++;
else if(Character.isLowerCase(str.charAt(i)))
l++;
else if(Character.isDigit(str.charAt(i)))
n++;
else if(Character.isSpace(str.charAt(i)))
s++;
}
System.out.print("\nUpper case = "+u+"\nLower case = "+l+"\nDigits = "+n+"\nBlank
Spaces = "+s);
}
}
/*OUTPUT :
Enter string : HI.. 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.
*/
import java.util.*;
class Vector_Demo
{public static void main(String args[])
{
Vector v = new Vector(4,2);
System.out.println("Intial size is: " +v.size());
System.out.println("Intial capacity is: " + v.capacity());
for(int i =0; i<args.length; i++)
{
v.addElement(new String(args[i])); }
Enumeration e = v.elements();
System.out.println("\nElements in vector:");
while(e.hasMoreElements())
{
}
System.out.println("Final size is: " +v.size());
System.out.println("Final capacity is: " + v.capacity());
}
}
/* OUTPUT
D:\OOPM>java Vector_Demo deep ramesh komal raj neel
*/
---------------------------------------------------------------------------------------------/*AIM : Write a Program to accept and display the month number. Throw an exception if
improper month number is entered. Make your own exception class to handle this exception.
*/
import java.io.*;
class NumberRangeException extends Exception
{
String msg;
NumberRangeException()
{
msg = new String("Exception : Enter a number between 1 and 12");
}
}
class My_Exception
{
public static void main (String args []) throws IOException
{
try{
InputStreamReader(System.in));
System.out.print("Enter month number : ");
int x = Integer.parseInt(obj.readLine());
if (x >= 1 && x <=12)
System.out.println(x+" is a valid month number");
else throw new NumberRangeException();
}
catch (NumberRangeException e)
{
System.out.println (e.msg);
}
}
}
/*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.
Consider a class network given. The class 'Admin' derives information from
the class 'Account' which in turn derives information from the 'Person' class. Write a program
to display 'Admin' object.*/
class Person
//super class
{
protected String name;
protected int code;
Person(String n, int c)
{
name=n;
code=c;
}
public void display()
{
System.out.println("Name of person is: "+name+"\nCode is: "+code);
}
}
class Account extends Person
{
//sub class
{
protected int exp;
Admin(String n,int c,int p,int e)
{
super(n,c,p);
exp=e;
}
public void display()
{
super.display();
System.out.println("Experience : "+exp);
}
}
class CompanyRecords
{
public static void main( String args[])
{
Admin m=new Admin("ABC",1001,10000,5);
m.display();
}
}
/* OUTPUT :
Name of person is: ABC
Code is: 1001
Salary : 10000
Experience : 5 */
------------------------------------------------------------------/*AIM : Write a program to display volume of sphere and hemisphere. Make use of abstract
class.
*/
import java.util.Scanner;
abstract class Calculate
{
protected double r;
protected double pi = 3.14;
abstract double volume();
}
class Sphere extends Calculate
{
double volume()
{
return((4.0/3.0) * pi * r* r * r);
}
}
class Hemisphere extends Calculate
{
double volume()
{
return((2.0/3.0) * pi * r * r * r);
}
}
class Volume
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
*/
*/
import java.util.Scanner;
interface Matrix
{
final static int M=5, N=5;
public void readMatrix();
public void displayMatrix();
public void addMatrix();
{
System.out.print(x[i][j]+ " ");
}
System.out.println();
}
System.out.println("Displaying Matrix 2 : ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(y[i][j]+ " ");
}
System.out.println();
}
}
public void addMatrix()
{
System.out.println("Displaying Addition of Matrices : ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
z[i][j]=x[i][j]+y[i][j];
System.out.print(z[i][j]+ " ");
}
System.out.println();
}
}
public void multMatrix()
{
System.out.println("Displaying Multiplication of Matrices :");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
z[i][j]=0;
for(int k=0;k<3;k++)
{
z[i][j]+=x[i][k]*y[k][j];
}
System.out.print(z[i][j]+ " ");
}
System.out.println();
}
}
public void transposeMatrix()
{
System.out.println("Displaying Transpose of Matrix 1 : ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(x[j][i]+ " ");
}
System.out.println();
}
}
}
class MatrixDemoInterface
{
public static void main(String args[])
{
MatrixOperations a =new MatrixOperations();
a.readMatrix();
a.displayMatrix();
a.transposeMatrix();
a.addMatrix();
a.multMatrix();
}
}
/*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
*/
*/
// face.html
<html>
<applet CODE = "FaceExample.class" WIDTH=200 HEIGHT=150>
</applet>
</html>
// FaceExample.java
import java.awt.*;
import java.applet.*;
public class FaceExample extends Applet
{
public void paint(Graphics g)
{
g.drawOval(20,20,70,30);
g.drawOval(110,20,70,30);
g.drawLine(100,50,100,80);
g.drawLine(70,100,130,100);
}
}
OUTPUT :
D: \OOP>javac FaceExample.java
D:\OOP>appletviewer face.html
*/
{
for(int i=1;i<=10;i++)
{
System.out.print(i);
try{
Thread.sleep(500);
}
catch(Exception e){}
}
}
}
class B implements Runnable
{
public void run()
{
for(int i=1;i<=10;i++)
{
System.out.print((char)(i+64));
try{
Thread.sleep(550);
}
catch(Exception e){}
}
}
}
class Multithreading
{
public static void main(String args[])
{
A a =new A();
a.start();
B b =new B();
Thread t=new Thread(b);
t.start();
}
}
/*OUTPUT :
1A2B3C4D5E6F7G8H9I10J
*/