Ttoppa
Ttoppa
THAMIZHTHENDRAL K
PROGRAM:
OUTPUT:
PROGRAM:
class binarys
{
public static void binarys(int arr[], int first, int last, int key)
{
int mid=(first+last)/2;
while(first<=last)
{
if(arr [mid]<key)
{
first=mid+1;
}
else if(arr [mid]==key)
{
System.out.println("Element is found at index:"+mid);
break;
}
else{
last=mid-1;
}
mid=(first+last)/2;
}
if (first>last){
System.out.println("Element is not found !");
}}
public static void main(String args[])
{
int arr[]={10,20,30,40,50};
int key=30;
int last=arr.length-1;
binarys(arr,0,last,key);
}}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
PROGRAM:
OUTPUT:
10
20
25
57
63
96
REG NO:622423104050
THAMIZHTHENDRAL K
PROGRAM:
import java.util.*;
public class insert
{
public static void main(String args[])
{
int []numArray={10,6,15,4,1,45};
System.out.println("original array:"+Arrays.toString(numArray));
for(int k=1;k<numArray.length-1;k++)
{
int temp=numArray[k];
int j=k-1;
while(j>=0 && temp <=numArray[j])
{
numArray[j=1]=numArray[j];
j=j-1;
}
numArray[j+1]=temp;
}
System.out.println("Sorted array:"+Arrays.toString(numArray));
}}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
PROGRAM:
import java.util.Stack;
public class Loki {
public static void main(String[] args) {
Stack stack=new Stack();
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
System.out.println("Top element is:"+stack.peek());
stack.pop();
stack.pop();
System.out.println("The stack size is:"+stack.size());
if(stack.empty())
{
System.out.println("The stack is empty");
}
else
{
System.out.println("The stack in not empty");
}
}
}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
PROGRAM:
import java.util.LinkedList;
import java.util.Queue;
class queue
{
public static void main(String args[])
{
Queue<String> queue=new LinkedList<String>();
queue.add("A");
queue.add("B");
queue.add("C");
queue.add("D");
System.out.println("the front element is:"+queue.peek());
queue.remove();
queue.remove();
System.out.println("the front element is:"+queue.peek());
System.out.println("the queue size is:"+queue.size());
if(queue.isEmpty())
{
System.out.println("the queue is empty");
}
else{
System.out.println("the queue is not empty");
}}}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
PROGRAM:
import java.util.Scanner;
class Employee {
public String empName, address, mailId, mobile, empId;
public double da, hra, pf, sc, gross, net;
Scanner scan = new Scanner(System.in);
void getEmpDetails() {
System.out.print("Enter Name: ");
empName = scan.nextLine();
System.out.print("Enter ID: ");
empId = scan.nextLine();
System.out.print("Enter Address: ");
address = scan.nextLine();
System.out.print("Enter Mail ID: ");
mailId = scan.nextLine();
System.out.print("Enter Mobile: ");
mobile = scan.nextLine();
}
void eval(float salary) {
da = 0.97 * salary;
hra = 0.1 * salary;
pf = 0.12 * salary;
sc = 0.001 * salary;
gross = da + hra + pf;
net = gross - pf - sc;
}
void disp() {
System.out.println("==========================================");
System.out.println(">>>>>>>>>>>>>>>>> Pay Slip <<<<<<<<<<<<<<<");
System.out.println("Name: " + empName);
System.out.println("ID: " + empId);
System.out.println("Address: " + address);
System.out.println("Mail ID: " + mailId);
System.out.println("Mobile: " + mobile);
System.out.println("DA: " + da);
System.out.println("HRA: " + hra);
System.out.println("PF: " + pf);
System.out.println("Staff Club: " + sc);
System.out.println("Gross Salary: " + gross);
System.out.println("Net Salary: " + net);
System.out.println("==========================================");
}}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
Main Menu
==========================================
Your Designation:
1. Programmer
2. Asst. Professor
3. Asso. Professor
4. Professor
==========================================
Enter Your Choice: 1
Enter Name: xyz
Enter ID: 2024
Enter Address: 12\2 small street
Enter Mail ID: [email protected]
Enter Mobile: 1234567890
Enter Your Salary: 12000
==========================================
>>>>>>>>>>>>>>>>> Pay Slip <<<<<<<<<<<<<<<
Name: xyz
ID: 2024
Address: 12\2 small street
Mail ID: [email protected]
Mobile: 1234567890
DA: 11640.0
HRA: 1200.0
PF: 1440.0
Staff Club: 12.0
Gross Salary: 14280.0
Net Salary: 12828.0
==========================================
Do you want to continue..?1:0 :0
REG NO:622423104050
THAMIZHTHENDRAL K
PROGRAM:
import java.util.*;
class AbsShape
{
public static void main(String agrs[])
{
int con;
Scanner scan=new Scanner(System.in);
do
{
System.out.println("\t\tMain Menu");
System.out.println("******************************************");
System.out.println("1.Rectangle\n2.Triangle\n3.Circle\n");
System.out.println("******************************************");
System.out.print("Enter your Choice: ");
int ch=scan.nextInt();
switch(ch)
{
case 1:
System.out.println("\tRECTANGLE");
shape r=new rectangle();
r.printArea();
break;
case 2:
System.out.println("\tTRIANGLE");
shape t=new triangle();
t.printArea();
break;
case 3:
System.out.println("\tCIRCLE");
shape c=new circle();
c.printArea();
break;
default:
System.out.println("Invalid choice");
}
System.out.println("\n******************************************");
System.out.print("Do you want continue again..?1:0 :");
con=scan.nextInt();
}
while(con!=0);
}
}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
Main Menu
******************************************
1.Rectangle
2.Triangle
3.Circle
******************************************
Enter your Choice: 3
CIRCLE
Enter Radius: 10
Area of Circle = 314.0
******************************************
Do you want continue again..?1:0 :0
REG NO:622423104050
THAMIZHTHENDRAL K
PROGRAM:
Import java.util.*;
interface Shape
{
Scanner scan=new Scanner(System.in);
void disp();
}
class Triangle implements Shape
{
double b,h,area;
public void disp()
{
System.out.print("Enter base : ");
b=scan.nextDouble();
System.out.print("Enter height : ");
h=scan.nextDouble();
area=0.5*b*h;
System.out.print("Area of Triangle : "+area);
}
}
class Rectangle implements Shape
{
double l,b,area;
public void disp()
{
System.out.print("Enter length : ");
l=scan.nextDouble();
System.out.print("Enter breadth : ");
b=scan.nextDouble();
area=l*b;
System.out.print("Area of Rectangle : "+area);
}
}
class Circle implements Shape
{
double r,area;
public void disp()
{
System.out.print("Enter radius : ");
r=scan.nextDouble();
area=3.14*r*r;
System.out.print("Area of Circle : "+area);
}}
REG NO:622423104050
THAMIZHTHENDRAL K
class InterfaceShape
{
public static void main(String args[])
{
int ch;
do
{
Scanner scan=new Scanner(System.in);
System.out.println("\n**************************************");
System.out.println("\t\tMain Menu");
System.out.println("**************************************");
System.out.println("\t1.Triangle\n\t2.Rectangle\n\t3.Circle");
System.out.println("**************************************");
System.out.print("\nEnter your Choice : ");
int op=scan.nextInt();
switch(op)
{
case 1:
{ Triangle ob=new Triangle();
ob.disp();
break; }
case 2:
{ Rectangle ob=new Rectangle();
ob.disp();
break; }
case 3:
{ Circle ob=new Circle();
ob.disp();
break; }
default:
System.out.println("Invalid...!");
}
OUTPUT:
**************************************
Main Menu
**************************************
1.Triangle
2.Rectangle
3.Circle
**************************************
PROGRAM:
import java.util.*;
import java.lang.*;
class MarkException extends Exception
{ MarkException(String a)
{
super(a);
}}
class students
{ public static void main(String args[])
{
int ch;
do
{ Scanner scan=new Scanner(System.in);
System.out.println("\n ");
System.out.println("\t Student Grade System");
System.out.println("\n ");
System.out.println("Enter student name:");
String s_name=scan.next();
System.out.println("Enter your mark:");
int m=scan.nextInt();
try
{
if(m>0 && m<=100)
{
if(m>90 && m<=100)
{ System.out.println("\'A\' Grade");
System.out.println("Excellent...!!!");
}
else if(m>80 && m<=90)
{
System.out.println("\'B\' Grade");
System.out.println("Very Good..!!");
}
else if(m>70 && m<=80)
{
System.out.println("\'C\' Grade");
System.out.println(" Good.!");
}
else if(m>60 && m<=70)
{
System.out.println("\'D\' Grade");
System.out.println("Satisfactory..!");
}
REG NO:622423104050
THAMIZHTHENDRAL K
else
{
System.out.println("\'U\' Grade");
System.out.println("You are failed...");
}
}else
throw new MarkException("Invalid Mark..!");
}
catch(MarkException e)
{
System.out.println("Exception Occurred..!");
}
finally
{
System.out.println("Thank you..!!!");
}
System.out.println("\n ");
System.out.println("\n Do you want to continue for next student..? 1:0 ::");
ch=scan.nextInt();
}
while(ch==1);
}}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
PROGRAM:
import java.util.*;
class even implements Runnable
{
public int x;
public even(int x)
{
this.x=x;
}
public void run()
{
System.out.println("New Thread "+x+"is EVEN and square of "+x+"is:"+x*x);
}}
class odd implements Runnable
{
public int x;
public odd(int x)
{
this.x=x;
}
public void run()
{
System.out.println("New Thread "+x+"is ODD and cube of "+x+"is:"+x*x*x);
}}
class A extends Thread
{
public void run()
{
int num=0;
Random r=new Random();
try
{
for(int i=0;i<5;i++)
{
num=r.nextInt(100);
System.out.println("Main Thread and generated number is:"+num);
if(num % 2==0)
{
Thread t1=new Thread(new even(num));
t1.start();
}
REG NO:622423104050
THAMIZHTHENDRAL K
else
{
Thread t2=new Thread(new odd(num));
t2.start();
}
Thread.sleep(1000);
System.out.println("
");
}}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}}}
public class ThreeThreads
{public static void main(String args[])
{
A a=new A();
a.start();
}}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
PROGRAM:
OUTPUT:
PROGRAM:
import java.io.*;
class copyfilez {
public static void main(String args[]) throws IOException {
int i;
FileInputStream fin = null;
FileOutputStream fout = null;
if (args.length != 2) {
System.out.println("Usage: CopyFile <source>
<destination>");
return;
}
System.out.println("Displaying contents of " + args[0] + "\n");
try {
fin = new FileInputStream(args[0]);
do {
i = fin.read();
if (i != -1)
System.out.print((char) i);
} while (i != -1);
} catch (IOException e) {
System.out.println("Error Reading File: " + e.getMessage());
} finally {
try {
if (fin != null) fin.close();
} catch (IOException e) {
System.out.println("Error Closing File: " + e.getMessage());
}
}
System.out.println("\nCopying contents of " + args[0] + " to "
+ args[1] + "\n");
try {
fin = new FileInputStream(args[0]);
fout = new FileOutputStream(args[1]);
do {
i = fin.read();
if (i != -1) fout.write(i);
} while (i != -1);
} catch (IOException e) {
System.out.println("I/O Error: " + e.getMessage());
}
REG NO:622423104050
THAMIZHTHENDRAL K
finally {
try {
if (fin != null) fin.close();
} catch (IOException e2) {
System.out.println("Error Closing Input File: " +
e2.getMessage());
}
try {
if (fout != null) fout.close();
} catch (IOException e2) {
System.out.println("Error Closing Output File: " +
e2.getMessage());
}
}
System.out.println("\nFile Copied\n");
System.out.println("\nDisplaying contents of " + args[1] +
"\n");
try {
fin = new FileInputStream(args[1]);
do {
i = fin.read();
if (i != -1)
System.out.print((char) i);
} while (i != -1);
} catch (IOException e) {
System.out.println("Error Reading File: " + e.getMessage());
} finally {
try {
if (fin != null) fin.close();
} catch (IOException e) {
System.out.println("Error Closing File: " + e.getMessage());
}
}
}
}
REG NO:622423104050
THAMIZHTHENDRAL K
OUTPUT:
hello world
Copying contents of first1.txt to second2.txt
File Copied
hello world