Ex No: 1 Substring Removal From A String Using String Buffer Class Date
Ex No: 1 Substring Removal From A String Using String Buffer Class Date
DATE:
Aim:
Procedure:
Coding:
import java.io.*;
class strbuf
{
public static void main(String args[])
{
StringBuffer sb=new StringBuffer("jav");
System.out.println("Before insert");
System.out.println(sb);
System.out.println("After insert");
System.out.println(sb.insert(0,"Welcome to "));
System.out.println("After append");
System.out.println(sb.append('a'));
System.out.println("Length of the string");
System.out.println(sb.length());
System.out.println("Change tyhe char");
System.out.println(sb.substring(0,5));
System.out.println("After delete"+sb.delete(0,5));
System.out.println("After replace:"+sb.replace(0,2,"Welcome"));
}
}
OUTPUT:
Aim:
3
EX NO: 2
DATE:
Procedure:
Coding:
import java.io.*;
import java.lang.*;
4
class test
{
void value(int h,int b)
{
System.out.println("Area of Triangle:"+0.5*b*h);
}
void value(int a,int b,int c)
{
System.out.println("Perimeter of triangle"+(a+b+c));
}
}
class triangle
{
public static void main(String args[])
{
String s;
try
{
test t=new test();
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter breath and height value");
s=br.readLine();
int b=Integer.parseInt(s);
s=br.readLine();
int h=Integer.parseInt(s);
t.value(b,h);
5
OUTPUT:
EX NO:3
7
DATE:
Aim:
Procedure:
Coding:
8
import java.util.*;
public class rand
{
Random r=new Random();
int i,j;
int a[]=new int[10];
public void gen_no()
{
System.out.print("\n\n\t Generated Random Number are...");
for(i=0;i<5;i++)
{
a[i]=r.nextInt(20);
System.out.print("\n\t"+a[i]);
}
}
public void sort()
{
int temp;
for(i=0;i<8;i++)
{
for(j=1;j<8-i;j++)
{
if(a[j-1]>a[j])
{
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}}}
10
OUTPUT:
11
EX NO 4
DATE:
Aim:
Procedure:
12
Coding:
import java.util.*;
class calendardemo
{
public static void main(String args[])
{
String
months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Jul","Aug","Sep","Oct","Nov","Dec
"};
System.out.print("\n\t\t Implementation of calender class");
System.out.print("\n\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Calendar c=Calendar.getInstance();
GregorianCalendar gc=new GregorianCalendar();
System.out.print("\n\t Date-->");
System.out.print(months[c.get(Calendar.MONTH)]);
System.out.print("-"+c.get(Calendar.DATE));
System.out.print("-"+c.get(Calendar.YEAR));
System.out.print("\n\n\t Time-->");
System.out.print(c.get(Calendar.HOUR)+":");
System.out.print(c.get(Calendar.MINUTE)+":");
System.out.print(c.get(Calendar.SECOND));
if(gc.isLeapYear(c.get(Calendar.YEAR)))
System.out.print("\n\n\t"+c.get(Calendar.YEAR)+"Is a Leap year");
else
System.out.print("\n\n\t"+c.get(Calendar.YEAR)+"Is not a Leap year");
}
}
Output:
13
14
EX NO: 5
DATE:
Aim:
Procedure:
15
Coding:
import java.io.*;
import java.lang.*;
class stringcompare
{
public static void main(String arg[])throws IOException
{
String s=new String();
char chars[];
char vowels[]={'a','e','i','o','u','A','E','I','O','U'};
int v=0,n=0,sp=0;
System.out.println("String Manipulation Using Character Array");
System.out.println("*****************************************");
System.out.println("Enter the String");
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
s=br.readLine();
System.out.println(s);
chars=s.toCharArray();
for(int j=0;j<s.length();j++)
{
if((chars[j]>47)&&(chars[j]<58))
n++;
else
if(((chars[j]>=65)&&(chars[j]<95))||((chars[j]>95)&&(chars[j]<122)))
{
for(int k=0;k<10;k++)
{
if(chars[j]==vowels[k])
v++;
}
}
else
sp++;
}
System.out.println("\n\n Vowels"+v);
System.out.println("\n\n Digits"+n);
System.out.println("\n\n Special character"+sp);
}}
16
Output:
17
EX NO:6
DATE:
Aim:
Procedure:
18
Coding:
import java.io.*;
import java.util.*;
class vectordemo
{
public static void main(String fr[])throws IOException
{
Vector vec=new Vector();
int n,i,j,k,pos=0,s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\n\n\t\t Implementation of vector class");
System.out.print("\n\t\t*********************************");
System.out.print("\n\n\t Enter the no.of elements:");
n=Integer.parseInt(br.readLine());
for(i=0;i<n;i++)
{
System.out.print("\n\n\t Enter the #"+(i+1)+"elements:");
k=Integer.parseInt(br.readLine());
vec.addElement(new Integer(k));
}
System.out.print("\n\n\t Displaying the vector:"+vec);
System.out.println("\n\t First Element in the vector:"+vec.firstElement());
System.out.println("\n\t Last Element in the vector:"+vec.lastElement());
System.out.println("\n\t Enter the element to be inserted:");
s=Integer.parseInt(br.readLine());
System.out.println("\n\t Enter the position to be inserted:");
pos=Integer.parseInt(br.readLine());
vec.insertElementAt(new Integer(s),pos-1);
System.out.println("\n\t Displaying vector after insertion:"+vec);
System.out.println("\n\t Enter the position to remove:");
pos=Integer.parseInt(br.readLine());
vec.removeElementAt(pos-1);
System.out.println("\n\t Vector after removal:"+vec);
System.out.println("\n Displaying using Enumeration...");
Enumeration e=vec.elements();
while(e.hasMoreElements())
System.out.println("\n\t\t\t"+e.nextElement());
}
}
19
Output:
20
EX NO: 7
Interface And Package
DATE:
Aim:
Procedure:
21
Coding:
Impinp package
import java.io.*;
import pack.*;
class impinp extends student implements marks
{
int m1,m2,m3,tot;
public void gets(int no1,int no2,int no3)
{
m1=no1;
m2=no2;
m3=no3;
tot=no1+no2+no3;
}
public void view()
{
System.out.print("\n\n\t Mark 1="+m1);
System.out.print("\n\n\t Mark 2="+m2);
System.out.print("\n\n\t Mark 3="+m3);
System.out.print("\n\n\t Total="+tot);
}
public static void main(String args[])throws IOException
{
System.out.println("\t\t\t Interfaces And Package");
System.out.println("\t\t\t*****************");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n Enter the Student Number: ");
int no=Integer.parseInt(br.readLine());
System.out.println("\n Enter the Student name: ");
String name=br.readLine();
System.out.println("\n\t Enter the mark 1:");
int m1=Integer.parseInt(br.readLine());
System.out.println("\n\t Enter the mark 2:");
int m2=Integer.parseInt(br.readLine());
System.out.println("\n\t Enter the mark 3:");
int m3=Integer.parseInt(br.readLine());
impinp imp=new impinp();
imp.get(no,name);
imp.display();
imp.gets(m1,m2,m3);
imp.view();
}}
Student pack
22
package pack;
public class student
{
int no;
String name;
public void get(int n,String s)
{
no=n;
name=s;
}
public void display()
{
System.out.println("\n\t The Student number is: "+no);
System.out.println("\n\t The Student name is: "+name);
}
public interface marks
{
public void gets(int no1,int no2,int no3);
public void view();
}
}
23
Output:
24
EX NO:9
DATE:
Aim:
Procedure:
Coding:
25
import java.lang.*;
class newthread implements Runnable
{
newthread()
{
Thread t=new Thread(this,"Demo Thread");
System.out.print("Child:"+t);
t.start();
}
public void run()
{
try
{
for(int i=5;i>0;i--)
{
System.out.print("\n\n\t Child:"+i);
Thread.sleep(500);
}
}
catch(InterruptedException i)
{
}
System.out.print("\n\n\t Child is in exist");
}
}
class threaddemo
{
public static void main(String arg[])
{
new newthread();
try
{
for(int i=5;i>0;i--)
{
System.out.print("\n\n\t Main:"+i);
Thread.sleep(100);
}
}
catch(InterruptedException i)
{
}
System.out.print("\n\n\t Main is in exist");
}
}
26
Output:
27
EX NO: 9
DATE:
Aim:
Procedure:
28
Coding;
import java.lang.*;
class inventory
{
static int q=100,r=0;
static public synchronized void request(int order)
throws InterruptedException
{
for(int i=1;i<=3;i++)
{
Thread.sleep(300);
if(order<=q)
{
System.out.println("\n\t Quantity Ordered:"+order);
q=q-order;
r=r+order;
System.out.println(" Quantity in hand:"+q);
System.out.println("\n\t Total order taken:"+r);
}
else
{
System.out.println("\n\t Ordered quantity more than in");
System.out.println("hand");
}
order=((int)(Math.random()*100));
}
}
public static void main(String args[ ]) throws InterruptedException
{
System.out.println("\t\t\t APPLICATION USING");
System.out.print("SYNCHRONIZATION");
System.out.println("\t\t\t ......................................");
System.out.print(".");
new ourthread();
Thread.sleep(50);
inventory.request((int)(Math.random()*100));
System.out.println("\n\t Existing from main thread...");
}
29
}
class ourthread extends Thread
{
ourthread()
{
super("Test thread");
System.out.println("\n\t Child thread:"+this);
start();
}
public void run()
{
try
{
inventory.request((int)(Math.random()*100));
}
catch(InterruptedException e)
{
System.out.println("\n\t"+e);
}
System.out.println("\n\t Child thread existing");
}
}
Output:
30
EX NO: 10
31
DATE:
Aim:
Procedure:
Coding:
import java.io.*;
32
class Ebill{
public static void main(String args[]) throws IOException {
File f = new File("Electricity.txt");
dos.writeDouble(amount);
dos.close();
33
Output:
34
35
EX NO: 11
Telephone Bill Preparation
DATE:
Aim:
Procdure:
Coding:
36
Output:
38
39
EX NO:14
EMAIL CREATION USING DATABASE
DATE:
Aim
Procedure:
Coding:
import java.sql.*;
40
import java.sql.DriverManager.*;
import java.io.*;
class inst
{
Connection con;
PreparedStatement ps;
Statement st;
ResultSet r;
int rs;
String str;
void inst1()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Test");
Statement stm=con.createStatement();
}
catch(Exception e)
{
System.out.println("\n\t Connection Error");
}
}
void addrec(int id,String str,int age,String emid)
throws SQLException
{
ps=con.prepareStatement("Insert into email values(?,?,?,?)");
ps.setInt(1,id);
ps.setString(2,str);
ps.setInt(3,age);
ps.setString(4,emid);
ps.executeUpdate();
System.out.println("\n\t Inserted");
con.setAutoCommit(true);
con.close();
}
41
case 2:
{
i.inst1();
System.out.println("\n\n\t\t Enter the);
System.out.print(personID to update:");
s=br.readLine();
pid=Integer.parseInt(s);
System.out.println("\n\n\t\t Enter the);
System.out.print(person ID,Name,Age,);
System.out.print(Email ID:");
name=br.readLine();
age=Integer.parseInt(s);
emid=br.readLine();
i.update(pid,name,age,emid);
break;
}
case 3:
{
i.inst1();
System.out.println("\n\n\t\t Enter the);
System.out.print(person ID to delete);
System.out.print(records...");
s=br.readLine();
pid=Integer.parseInt(s);
i.del(pid);
}
case 4:
{
i.inst1();
i.disp();
break;
}
case 5:
System.out.println(\t ***END***);
break;
default:
44
Output:
DATABASE MANIPULATION
45
-----------------------------------------
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. Exit
Enter your choice: 1
Enter the person ID, Name, Age, Email ID
2100
john
18
[email protected]
Inserted
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 1
Enter the person ID, Name, Age, Email ID
2101
gnp
19
[email protected]
Inserted
1. INSERT
46
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 4
Id
Name Age
Email-Id
2100 john 18
2101 gnp
19
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 3
Enter the person ID to delete records: 2100
Id
Name Age
2100 john 18
Email-Id
[email protected]
record deleted
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 5
***END***
47