1.write A Java Program For Sorting A Given List of Names in Ascending Order Using Command Line Arguments
1.write A Java Program For Sorting A Given List of Names in Ascending Order Using Command Line Arguments
Write a java program for sorting a given list of names in ascending order using
command line arguments
import java.lang.*;
import java.io.*;
import java.util.*;
class Sort
{
public static void main(String arg[ ]) throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter the size");
int n=Integer.parseInt(dis.readLine());
String array[ ]=new String[n];
System.out.println("enter names");
for(int i=0;i{
array[i]=dis.readLine();
}
for(int i=0;i{
for(int j=0;j{
if(array[j].compareTo(array[j+i])>0)
{
String temp=array[j];
array [j]=array[j+1];
array[j+1]=temp;
}
}
}
Output
Java sorting Harish Ramesh Mahesh Rakesh
Sorted order is
Ramesh
Rakesh
Mahesh
Harish
Java sorting sai hari teja ravi sandeep
Sorted order is
teja
sandeep
sai
ravi
hari
for(int j=0;j<3;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println("\n");
}
System.out.println("\n");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println("\n");
}
System.out.println("\n");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println("\n");
}
}
}
Output:
Enter the first matrix:
123456789
30
24
18
84
69
54
138
114
90
s.add(10,15);
s.add(10,20,30);
}
}
Output:
Sum of two=25
Sum of three=60
Method overriding
//dynamic polymorphism
class A
{
void cal(double x)
{
System.out.println("square value="+(x*x));
}
}
class B extends A
{
void cal(double x)
{
System.out.println("square root="+Math.sqrt(x));
}
}
class Polymorphism
{
public static void main(String args[])
{
A a=new A();
a.cal(15);
}
}
Output:Square value=225.0
}
interface basicinfo
{
}
interface otherinfo
{
InputStreamReader(System.in));
System.out.print(Blanguage+"\t\t"+Byear+"\t"+Bprice+"\t");
System.out.print(Bcopies+"\t"+Bpublisher+"\t\t");
}
}
class interfaceEg
{
public static void main(String s[])throws IOException
{
book it[];
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("How much entries..?");
int k=Integer.parseInt(br.readLine());
it=new book[k];
for(int i=0;i<k;i++)
{ it[i]=new book();
}
for(int i=0;i<k;i++)
{
int j=i+1;
System.out.println("ENTER DETAILS OF THE BOOK : "+j);
it[i].getbookdata();
it[i].getbasicdata();
it[i].getotherdata();
System.out.println("\n\n***********-----------------Book
details-----------------************\n");
System.out.println("Book\tAuthor\tLanguage\tYear\tPrice\tCopies
\tPublisher");
System.out.println("............................................................................");
for(int i=0;i<k;i++)
{
it[i].putbookdata();
it[i].putbasicdata();
it[i].putotherdata();
}
}
}
Output:
package folder;
import java.io.*;
public class big
{
public int empno;
public String empname=new String( );
public String designation=new String( );
public int basicpay;
public double hra,da,pf,lic,grosspay,netpay;
public void getData( )
{
try
{
DataInputStream ds=new DataInputStream(System.in);
System.out.println("Enter the Employee number: ");
empno=Integer.parseInt(ds.readLine( ));
System.out.println("Enter the Employee name: ");
empname=ds.readLine( );
System.out.println("Designation: ");
designation=ds.readLine( );
System.out.println("Enter Basicpay: ");
basicpay=Integer.parseInt(ds.readLine( ));
}
catch(Exception e)
{}
}
public void Calculate( )
{
if(designation.equals("Engineer"))
{
hra=basicpay*0.20;
da=basicpay*0.15;
pf=basicpay*0.12;
lic=basicpay*0.25;
}
else if(designation.equals("Analyst"))
{
hra=basicpay*0.20;
da=basicpay*0.15;
pf=basicpay*0.12;
lic=basicpay*0.25;
}
else
{
hra=basicpay*0.10;
da=basicpay*0.14;
pf=basicpay*0.12;
lic=basicpay*0.10;
}
grosspay=basicpay+hra+da;
netpay=grosspay-(pf+lic);
}
public void Display( )
{
System.out.println("Employee number: "+empno);
System.out.println("Employee name: "+empname);
System.out.println("Designation: "+designation);
System.out.println("Basicpay: "+basicpay);
System.out.println("HRA: "+hra);
System.out.println("DA: "+da);
System.out.println("PF: "+pf);
System.out.println("LIC: "+lic);
System.out.println("Grosspay: "+grosspay);
System.out.println("Netpay: "+netpay);
}
}
MAIN FUNCTION
----------------------import floder.big;
public class emp
{
public static void main(String args[ ])
{
System.out.println(EMPLOYEE SALARY DETAILS);
System.out.println(****************************);
big ob=new big( );
ob.getData( );
ob.Calculate( );
ob.Display( );
}
}
OUTPUT:
RUN 1:
C:\jdk1.3\bin\ct>javac emp1.java
C:\jdk1.3\bin\ct>java emp1
EMPLOYEE SALARY DETAILS
****************************
Enter the Employee number:
25
Enter the Employee name:
Rajesh
Designation:
Engineers
Enter Basicpay:
1250
Employee number: 25
Employee name: Rajesh
Designation: Engineer
Basicpay: 1250
HRA: 250.0
DA: 187.5
PF: 150.0
LIC: 312.5
Grosspay: 1687.5
Netpay: 1225.0
RUN 2:
C:\jdk1.3\bin\ct>javac emp1.java
C:\jdk1.3\bin\ct>java emp1
EMPLOYEE SALARY DETAILS
****************************
Enter the Employee number:
26
Enter the Employee name:
Ravi
Designation:
Analyst
Enter Basicpay:
875
Employee number: 26
Employee name: Ravi
Designation: Analyst
Basicpay: 875
HRA: 175.0
DA: 131.25
PF: 105.0
LIC: 218.75
Grosspay: 1181.25
Netpay: 857.5
RUN 3:
C:\jdk1.3\bin\ct>javac emp1.java
C:\jdk1.3\bin\ct>java emp1
EMPLOYEE SALARY DETAILS
****************************
Enter the Employee number:
35
Enter the Employee name:
Raja
Designation: Superviser
Enter Basicpay:
1000
Employee number: 35
Employee name: Raja
Designation: Supervisor
Basicpay: 1000
HRA: 100.0
DA: 140.0
PF: 120.0
LIC: 100.0
Grosspay: 1240.0
Netpay: 1020.0
}
}
class MultiThreadDemo
{
Output:
New Thread :Thread[One,5,main]
New Thread : Thread[Two,5,main]
One:5
Two:5
New Thread : Thread[Three,5,main]
Three:5
One:4
Three:4
Two:4
One:3
Three:3
Two:3
One:2
Three:2
Two:2
One:1
Three:1
Two:1
One exiting
Three exiting
Two exiting
Main Thread Exiting
notifyAll();
return contents;
}
public synchronized void put(int value) {
while (available == true) {
try {
wait();
}
catch (InterruptedException e) {
}
}
contents = value;
available = true;
notifyAll();
}
}
}
public void run() {
int value = 0;
for (int i = 0; i < 10; i++) {
value = cubbyhole.get();
System.out.println("Consumer #"
+ this.number
+ " got: " + value);
}
}
}
cubbyhole.put(i);
System.out.println("Producer #" + this.number
+ " put: " + i);
try {
sleep((int)(Math.random() * 100));
} catch (InterruptedException e) { }
}
}
}
Output:
Producer #1 put: 0
Consumer #1 got: 0
Producer #1 put: 1
Consumer #1 got: 1
Producer #1 put: 2
Consumer #1 got: 2
Producer #1 put: 3
Consumer #1 got: 3
Producer #1 put: 4
Consumer #1 got: 4
Producer #1 put: 5
Consumer #1 got: 5
Producer #1 put: 6
Consumer #1 got: 6
Producer #1 put: 7
Consumer #1 got: 7
Producer #1 put: 8
Consumer #1 got: 8
Producer #1 put: 9
Consumer #1 got: 9
Output:
C:\jdk1.3\bin\ct>javac Face.java
C:\java1.3\bin\ct>appletviewer Face.java
11. Create and Manipulate Labels, Lists, Text Fields, Text Areas & Panels