PROGARM FOR CREATE A EMPLOYEE DETAILS

import java.lang.*;
import java.io.*;
class Employee
{
int empno;
String name;
Employee()
{
try
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("name of the employee
);
name=d.readLine();
System.out.println("Employy no:");
empno=Integer.parseInt(d.readLine());
}
catch(IOException e)
{
System.out.println("ioerror");
}
}
void Display()
{
}
}

class manager extends Employee
{
String desig;
int bp;
int hra;
int ta=100,da,inc;
manager()
{
try
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("salary is
);
bp=Integer.parseInt(d.readLine());
System.out.println("desig of the employee
);
desig=d.readLine();
hra=(bp*10)/100;
da=(bp*5)/100;
inc=(bp*15)/100;
}
catch(IOException e1)
{

System.out.println("error");
}
}
void Display()
{


System.out.println(name+" "+empno+" "+desig+" "+" "+(bp+hra+da+ta+inc)
);

}
}
class Typist extends Employee
{

int bp;
String desig;
int hra;
int ta=0,da,inc;
Typist()
{
try
{
DataInputStream d=new
DataInputStream(System.in);
System.out.println("salary is
);
bp=Integer.parseInt(d.readLine());
System.out.println("desig of the employee
);
desig=d.readLine();
hra=(bp*8)/100;
da=(bp*4)/100;
inc=(bp*10)/100;
}
catch(IOException e1)
{
System.out.println("error");
}
}
void Display()
{

System.out.println(name+" "+empno+" "+desig+" "+" "+(bp+hra+da+ta+inc)
);

}
}

public class lab1
{
public static void main(String args[]) throws IOException
{
manager m=new manager();
Typist t=new Typist();
System.out.println(" EMPLOYEE DETAILS" );
System.out.println(" ~~~~~~~~~~~~~~~~" );
System.out.println("Name Code Designation
Salary ");
System.out.println("~~~~ ~~~~ ~~~~~~~~~~~
~~~~~~ ");
m.Display();
t.Display();

}
}

Is it possible to stop an object from being created during construction?

Yes, have the constructor throw an exception. Formally, an object _will_ be created (since the constructor is a method invoked after the actual method creation), but nothing useful will be returned to the program, and the dead object will be later reclaimed by Garbage Collector.

But the clean way is that you leave calls to the constructor to a static factory method which can check the parameters and return null when needed.

Note that a constructor - or any method in general - throwing an exception will not "return null", but will leave the "assign target" as it was.

Selection Sort

import java.io.*;
class select
{
public static void main(String args[])throws IOException
{
int[] array = new int[100];
int max = 9;
int low , temp;
int a = 0;

try
{
BufferedReader keyb = new BufferedReader (new
InputStreamReader(System.in));
System.out.print("Enter max number to be sort:");
max = Integer.parseInt(keyb.readLine());
for (int x = 0 ; x <>
{
System.out.print("Enter number:");
array[x] = Integer.parseInt(keyb.readLine());
}
for (int m = 0 ; m <>
{

System.out.print(array[m] + " ");
}
System.out.print("
);

//for (int a = max - 1; a > 0; a--)
{

for( int b = 0 ; b <>
{
low = array[b];
for (int c = b ; c <>
{
if (array[c] <>
{
low = array[c];
//System.out.print("<" + b + "><" + c + "><" + low + ">
);

}
else
{
// System.out.print("<" + b + "><" + c + "><" + low + ">
);

}


for (int d = b ; d <>
{
if (array[d] == low)
{
temp = array[b];
array[b] = array[d];
array[d] = temp;
//System.out.print("*" + c + "*");
}
}
}

System.out.print("
);

for (int m = 0 ; m <>
{

System.out.print(array[m] + " ");
}

System.out.print("
);

}
}
}
catch (IOException e)
{
System.out.println("System Error");
}
catch (NumberFormatException er)
{
System.out.println("Kindly enter a number");
}

Simple Program in Java to Implement Multithreading

import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;

class test extends Frame implements ActionListener,Runnable
{
int lower,upper;
Label l1=new Label("ODD");
Label l2=new Label("EVEN");
List lb1=new List();
List lb2=new List();
Button b2=new Button("EXIT");
test(int low,int up)
{
lower = low;
upper = up;
setLayout(new FlowLayout());
setSize(700,700);
setTitle("Thread Demo");
setVisible(true);
add(l1);add(lb1);add(l2);add(lb2);add(b2);
b2.addActionListener(this);
Thread t=new Thread(this);
t.start();


addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0); }
}
);

}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b2)
System.exit(0);
}
public void run()
{
try
{
if((lower % 2) != 0)
{
lower = lower + 1;
}
while(lower <= upper)
{
Thread.sleep(1000);
lb2.add(String.valueOf(lower));
lower += 2;
Thread.sleep(500);
}
}catch(Exception e){}
}

public static void main(String args[])
{
int lower,upper;
lower = Integer.parseInt(args[0]);
upper = Integer.parseInt(args[1]);
test ob = new test(lower,upper);

if((lower % 2) == 0)
{
lower = lower + 1;
}

try
{
while(lower <= upper)
{
Thread.sleep(1000);
ob.lb1.add(String.valueOf(lower));
lower = lower + 2;
Thread.sleep(500);
}
}
catch(Exception e){}
}

}

Thread Method

class A extends Thread{
public void run(){
System.out.println("Thread A has started");
for (int i=0;i<=5;i++){
System.out.println("From thread A:i =" +i);
}
System.out.println("Exit from A");
}
}
class B extends Thread{
public void run(){
System.out.println("Thread B has started");
for (int j=0;j<=5;j++){
System.out.println("From thread B:j =" +j);
if(j==3)
stop();
}
System.out.println("Exit from B");
}
}
class C extends Thread{
public void run(){
System.out.println("Thread C has started");
for (int k=0;k<=5;k++){
System.out.println("From thread C:k =" +k);
if(k==1)
try{
sleep(100);
}catch(Exception e){

}
}
System.out.println("Exit from C");
}
}
class ThreadMethods{
public static void main(String args[]){
A ta = new A();
B tb = new B();
C tc = new C();
tc.setPriority(Thread.MAX_PRIORITY);
ta.setPriority(Thread.MIN_PRIORITY);
System.out.println("Start thread A");
ta.start();
System.out.println("Start thread B");
tb.start();
System.out.println("Start thread C");
tc.start();
System.out.println("End of main Thread");
}
}

Creating marklist In Java

import java.io.*;
public class Stud1{
private int mark1,mark2,mark3,result;
private float per;
private String name;
public Stud1(String name,int mark1,int mark2,int mark3){
this.name=name;
this.mark1=mark1;
this.mark2=mark2;
this.mark3=mark3;
}
public void calculate(){
result=mark1+mark2+mark3;
per=(float)result/300*100;
System.out.println("Name Of Student : "+this.name);
System.out.println("Result : "+result);
System.out.println("Percentage : "+per);
}
public static void main(String args[]){
Stud1 s=new Stud1("Avinash",79,78,79);
s.calculate();
Demo2 n= new Demo2();
n.defBelong();
}
}

Program to find Vowels

public class SwitchDemo1{
public void isVowel(char c){
switch(c){
case 'a' :
case 'e' :
case 'o' :
case 'i' :
case 'u' :
case 'A' :
case 'E' :
case 'O' :
case 'I' :
case 'U' :
System.out.println("Entered Charecter is Vowel");
break;
default :
System.out.println("Entered Charecter is Consonent");
break;
}
}
public static void main(String args[]){

SwitchDemo1 s= new SwitchDemo1();
s.isVowel('a');
s.isVowel('e');
s.isVowel('d');
s.isVowel('s');
s.isVowel('o');
}
}

Program to calculate area of rectangle

class RectArea{
float length,breadth;
double area;
void setValue(float l,float b){
length=l;
breadth=b;
}
void calculate(){
area=(double)length*breadth;
System.out.println("Area of Rectangle : "+area);
}
}
class Rect{
public static void main(String args[]) {
RectArea r=new RectArea();
r.setValue(12,20);
r.calculate();
}
}

Operator In Java

class OperatorUse{
public static void main(String args[]){
int a=5,b=3;
int c=1010;
System.out.println("a & b = "+(a &b));
System.out.println("a | b = "+(a |b));
System.out.println("a ^ b = "+(a ^b));
System.out.println("a << b = "+(c <<2));
System.out.println("a >> b = "+(c >>2));
System.out.println("a >>> b = "+(c >>>2));
}
}

Function Overloading In Java

class FunctionOverloading{
int a;
FunctionOverloading(){
a=10;
}
void volume(){
System.out.println("Valume = " +(a * a * a));
}
int volume(int i){
return(i*i*i);
}
float volume(float i){
return(i*i*i);
}
public static void main(String args[]){
int intVolume;
float floatVolume;
FunctionOverloading f=new FunctionOverloading();
f.volume();
intVolume=f.volume(5);
System.out.println("Valume = " +intVolume);
floatVolume=f.volume(2.3f);
System.out.println("Valume = " +floatVolume);
}
}

Parent & Child class in JAVA

class Parent{
int i,j;
Parent(int a,int b){
i=a;
j=b;
}
void show(){
System.out.println("Value of i = "+i);
System.out.println("Value of j = "+j);
}
}
class Child extends Parent
{
int k=52;
Child(int n,int m,int o) {
super(m,o);
k=n;
}
void show(){
super.show();
System.out.println("Value of k = "+k);
}
public static void main(String args[]){
Child b=new Child(12,45,32);
b.show();
}
}

Creating Bill Program

//class buuldin g with set and get type command and
//use of Default Constructor
public class Bill{
private int bno;
private int bamt;
public Bill(){
bno=20;
bamt=3200;
}
public void setBillNo(int i){
if(i>0 && i<1000){
bno=i;
}else{
System.out.println("invalid Bill Number");
}
}public void getBillNo(){
System.out.println("Bill No. : \t"+bno);
}
public void setBillAmt(int i){
if(i>500 && i<5000){
bamt=i;
}
else{
System.out.println("Invalide Amount");
}
}
public void getBillAmt(){
System.out.println("Bill Amount : \t"+bamt);
}
public static void main(String args[]){
Bill b1=new Bill(),b2=new Bill();
b2.getBillNo();
b2.getBillAmt();
b1.setBillNo(54);
b1.getBillNo();
b1.setBillAmt(4000);
b1.getBillAmt();
}
}

Arrays Input In Java

import java.io.*;
class ArrayInput{
public static void main(String args[]) throws IOException {
int arr1[]=new int[5];
int arr2[]=new int[5];
int arr3[][]=new int[5][5];
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String str;
System.out.println("Enter arr1 elements for arr1[0] to arr1[4]");
for(int i=0;i<5;i++){
str=br.readLine();
arr1[i]=Integer.parseInt(str);
}
System.out.println("Enter arr2 elements for arr2[0] to arr2[4]");
for(int i=0;i<5;i++){
str=br.readLine();
arr2[i]=Integer.parseInt(str);
}
for(int i=0 ;i<5;i++){
for(int j=0;j<5;j++){
arr3[i][j]=arr1[i]*arr2[j];
}
}
System.out.println("Ent1ered arr3 elements are ");
for(int i=0 ;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(" "+arr3[i][j]);
System.out.print("\t");
}
System.out.println();
}
}
}

Arrays In Java

class ArrayExample
{
public static void main(String args[]) throws Exception
{
int arr[]=new int[5];
arr[0]=45;
arr[1]=24;
arr[2]=39;
arr[3]=25;
arr[4]=12;
System.out.println("Array elements are :");
for(int i=0;i<5;i++)
{
System.out.println("Arr["+ i +"] = " +arr[i]);
}
}
}

FOR LOOP In Java

A for loop is used to repeat a statement until a condition is met. Although for loops fre-
quently are used for simple iteration in which a statement is repeated a certain number of
times, for loops can be used for just about any kind of loop.
The for loop in Java looks roughly like the following:
for (initialization; test; increment) {
statement;
}
The start of the for loop has three parts:
1. initialization is an expression that initializes the start of the loop. If you have a
loop index, this expression might declare and initialize it, such as int i = 0.
Variables that you declare in this part of the for loop are local to the loop itself;
they cease to exist after the loop is finished executing. You can initialize more than
one variable in this section by separating each expression with a comma. The state-
ment int i = 0, int j = 10 in this section would declare the variables i and j,
and both would be local to the loop.
2. test is the test that occurs before each pass of the loop. The test must be a
Boolean expression or a function that returns a boolean value, such as i <>
the test is true, the loop executes. When the test is false, the loop stops execut-
ing.
3. increment is any expression or function call. Commonly, the increment is used to
change the value of the loop index to bring the state of the loop closer to returning
false and stopping the loop. The increment takes place after each pass of the loop.
Similar to the initialization section, you can put more than one expression in
this section by separating each expression with a comma.




/*Write a program to Find Factorial of Given no. */
class Factorial{
public static void main(String args[]){
int num = 5;
int result = 1;
int result2 = 1;
//using while loop
while(num>0){
result = result * num;
num--;
}
//using for loop
num = 5;
for(int i=num;i>=1;i--){
result2=result2*i;
}
System.out.println("Factorial of Given no. is : "+result);
System.out.println("Factorial of Given no. is : "+result2);
}
}

Display DIGIT Triangle

0

1 0

1 0 1

0 1 0 1 */

class Output2{

public static void main(String args[]){

for(int i=1;i<=4;i++){

for(int j=1;j<=i;j++){

System.out.print(((i+j)%2)+" ");

}

System.out.print("\n");

}

}

}

program to find average of consecutive N Odd numbers and Even numbers

class EvenOdd_Avg{

public static void main(String args[]){

int n = Integer.parseInt(args[0]);

int cntEven=0,cntOdd=0,sumEven=0,sumOdd=0;

while(n > 0){

if(n%2==0){

cntEven++;

sumEven = sumEven + n;

}

else{

cntOdd++;

sumOdd = sumOdd + n;

}

n--;

}

int evenAvg,oddAvg;

evenAvg = sumEven/cntEven;

oddAvg = sumOdd/cntOdd;

System.out.println("Average of first N Even no is "+evenAvg);

System.out.println("Average of first N Odd no is "+oddAvg);



}

}

program to generate Harmonic Series.

Example :

Input - 5

Output - 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.28 (Approximately) */

class HarmonicSeries{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

double result = 0.0;

while(num > 0){

result = result + (double) 1 / num;

num--;

}

System.out.println("Output of Harmonic Series is "+result);

}

}

switch case Program

Example :

Input - 124

Output - One Two Four */



class SwitchCaseDemo{

public static void main(String args[]){

try{

int num = Integer.parseInt(args[0]);

int n = num; //used at last time check

int reverse=0,remainder;

while(num > 0){

remainder = num % 10;

reverse = reverse * 10 + remainder;

num = num / 10;

}

String result=""; //contains the actual output

while(reverse > 0){

remainder = reverse % 10;

reverse = reverse / 10;

switch(remainder){

case 0 :

result = result + "Zero ";

break;

case 1 :

result = result + "One ";

break;

case 2 :

result = result + "Two ";

break;

case 3 :

result = result + "Three ";

break;

case 4 :

result = result + "Four ";

break;

case 5 :

result = result + "Five ";

break;

case 6 :

result = result + "Six ";

break;

case 7 :

result = result + "Seven ";

break;

case 8 :

result = result + "Eight ";

break;

case 9 :

result = result + "Nine ";

break;

default:

result="";

}

}

System.out.println(result);

}catch(Exception e){

System.out.println("Invalid Number Format");

}

}

}

program to find whether no. is palindrome or not.

Example :

Input - 12521 is a palindrome no.

Input - 12345 is not a palindrome no. */

**********************************
CODE :

class Palindrome
{


public static void main(String args[]){

int num = Integer.parseInt(args[0]);

int n = num; //used at last time check

int reverse=0,remainder;

while(num > 0){

remainder = num % 10;

reverse = reverse * 10 + remainder;

num = num / 10;

}

if(reverse == n)

System.out.println(n+" is a Palindrome Number");

else

System.out.println(n+" is not a Palindrome Number");

}

}

Program to Find whether number is Prime or Not.

class PrimeNo{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

int flag=0;

for(int i=2;i
if(num%i==0)

{

System.out.println(num+" is not a Prime Number");

flag = 1;

break;

}

}

if(flag==0)

System.out.println(num+" is a Prime Number");

}

}


program to find whether given no. is Armstrong or not.

class Armstrong{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

int n = num; //use to check at last time

int check=0,remainder;

while(num > 0){

remainder = num % 10;

check = check + (int)Math.pow(remainder,3);

num = num / 10;

}

if(check == n)

System.out.println(n+" is an Armstrong Number");

else

System.out.println(n+" is not a Armstrong Number");

}

}



Output :

Input - 153

Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no.

program to Display Invert Triangle.

class InvertTriangle{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

while(num > 0){

for(int j=1;j<=num;j++){

System.out.print(" "+num+" ");

}

System.out.print("\n");

num--;

}

}

}


Output :

5 5 5 5 5

4 4 4 4

3 3 3

2 2

1

program to generate a Triangle.

class Triangle{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

for(int i=1;i<=num;i++){

for(int j=1;j<=i;j++){

System.out.print(" "+i+" ");

}

System.out.print("\n");

}

}

}


OUTPUT :

1

2 2

3 3 3

4 4 4 4

program to convert given no. of days into months and days.

class DayMonthDemo{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

int days = num%30;

int month = num/30;

System.out.println(num+" days = "+month+" Month and "+days+" days");

}

}



O/P :

Input - 69

Output - 69 days = 2 Month and 9 days *

program to Swap the values

class Swap{

public static void main(String args[]){

int num1 = Integer.parseInt(args[0]);

int num2 = Integer.parseInt(args[1]);

System.out.println("\n***Before Swapping***");

System.out.println("Number 1 : "+num1);

System.out.println("Number 2 : "+num2);

//Swap logic

num1 = num1 + num2;

num2 = num1 - num2;

num1 = num1 - num2;

System.out.println("\n***After Swapping***");

System.out.println("Number 1 : "+num1);

System.out.println("Number 2 : "+num2);

}

}

Program to Display Multiplication Table In java

class MultiplicationTable{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

System.out.println("*****MULTIPLICATION TABLE*****");

for(int i=1;i<=num;i++){

for(int j=1;j<=num;j++){

System.out.print(" "+i*j+" ");

}

System.out.print("\n");

}

}

}

program to Concatenate string using for Loop

class Join{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

String result = " ";

for(int i=1;i<=num;i++){

result = result + i + " ";

}

System.out.println(result);

}

}

program to find Fibonacci series of a given number in Java.

class Fibonacci{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);
//taking no. as command line argument.

System.out.println("*****Fibonacci Series*****");

int f1, f2=0, f3=1;

for(int i=1;i<=num;i++){

System.out.print(" "+f3+" ");

f1 = f2;

f2 = f3;

f3 = f1 + f2;

}

}

}

program to Reverse a given number in java

class Reverse{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);
//take argument as command line

int remainder, result=0;

while(num>0){

remainder = num%10;

result = result * 10 + remainder;

num = num/10;

}

System.out.println("Reverse number is : "+result);

}

}

program to Find Factorial of Given number in Java

class Factorial
{

public static void main(String args[])
{

int num = Integer.parseInt(args[0]);
//take argument as command line

int result = 1;

while(num>0)
{

result = result * num;

num--;

}

System.out.println("Factorial of Given no. is : "+result);

}

}

Program to find SUM AND PRODUCT of a given Digit.

class Sum_Product_ofDigit{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);
//taking value as command line argument.

int temp = num,result=0;

//Logic for sum of digit

while(temp>0){

result = result + temp;

temp--;

}

System.out.println("Sum of Digit for "+num+" is : "+result);

//Logic for product of digit

temp = num;

result = 1;

while(temp > 0){

result = result * temp;

temp--;

}

System.out.println("Product of Digit for "+num+" is : "+result);

}

}

program to generate 5 Random nos. between 1 to 100, and it should not follow with decimal point.

class RandomDemo
{

public static void main(String args[])
{

for(int i=1;i<=5;i++)
{

System.out.println((int)(Math.random()*100));

}

}

}

program that will read a float type value from the keyboard and print small number & Largest Integer

class ValueFormat{

public static void main(String args[]){

double i = 34.32; //given number

System.out.println("Small Integer not greater than the number : "+Math.ceil(i));

System.out.println("Given Number : "+i);

System.out.println("Largest Integer not greater than the number : "+Math.floor(i));

}

Calculator In Java

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class CalculatorApplet extends Applet implements ActionListener
{
private Button keysArray[];
private Panel keyPad;
private TextField lcdField;
private double result;
private boolean first;
private boolean foundKey;
static boolean clearText;
private int prevOperator;

public void init()
{
lcdField = new TextField(20);
keyPad = new Panel ();
keysArray = new Button[17];
result = 0.0;
prevOperator = 0;
first = true;
clearText = true;

//Set frame layout manager setLayout(new BorderLayout());

lcdField.setEditable(false);

//Create buttons
for (int i = 0; i <=9; i++) keysArray[i] = new Button(String.valueOf(i)); keysArray[10] = new Button("/"); keysArray[11] = new Button("*"); keysArray[12] = new Button("-"); keysArray[13] = new Button("+"); keysArray[14] = new Button("="); keysArray[15] = new Button("."); keysArray[16] = new Button("CLR"); //Set panel layout manager keyPad.setLayout(new GridLayout (4,4)); //Add button to keyPad panel for (int i = 7; i <=10; i++) //adds Button 7,8,9, and divide to Panel keyPad.add(keysArray[i]); for (int i = 4; i <6; i =" 1;" i =" 15;">=13; i--)
keyPad.add(keysArray[i]); //adds decimal point, equal, and addition
ke
ys Panel

add(lcdField, BorderLayout.NORTH); //adds text field to top of
Frame
add(keyPad, BorderLayout.CENTER); //adds Panel to center of Frame
add(keysArray[16], BorderLayout.EAST); //adds Clear key to right
side
of applet

for(int i = 0; i <>
keysArray[i].addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
foundKey = false;

//Search for the key pressed
for (int i = 0; i <>
if(e.getSource() == keysArray[i]) //key match found
{
foundKey = true;
switch(i)
{
case 0: case 1: case 2: case 3: case 4: //number buttons
case 5: case 6: case 7: case 8: case 9: //0-9
case 15:
if (clearText)
{
lcdField.setText("");
clearText = false;
}
lcdField.setText(lcdField.getText() +
keysArray[i].getLabel());
break;

case 10:// divide button
case 11:// multiply button
case 12:// minus button
case 13:// plus button
case 14:// equal button
clearText = true;
if (first) // First operand
{
if(lcdField.getText().length()==0)
result = 0.0;
else
result = Double.valueOf(lcdField.getText()).doubleValue();

first = false;
prevOperator = i; //save previous operator
}
else //second operand already enter, so calculator total
{
switch(prevOperator)
{
case 10: //divide Button
result /= Double.valueOf(lcdField.getText()).
doubleValue();
break;
case 11: //multiply Button
result *= Double.valueOf(lcdField.getText()).
doubleValue();
break;
case 12: //minus button
result -= Double.valueOf(lcdField.getText()).
doubleValue();
break;
case 13: //plus button
result += Double.valueOf(lcdField.getText()).
doubleValue();
break;
}
lcdField.setText(Double.toString(result));
if (i==14)//equal button
first = true;
else
prevOperator = i; //save previous opetator
}
break;

case 16://Clear button
clearText = true;
first = true;
lcdField.setText("");
result = 0.0;
prevOperator = 0;
break;
}
}
}
}

Find Minimum of 2 nos. using conditional operator

class Minof2{

public static void main(String args[]){

//taking value as command line argument.

//Converting String format to Integer value

int i = Integer.parseInt(args[0]);

int j = Integer.parseInt(args[1]);

int result = (i
System.out.println(result+" is a minimum value");

}

}

Program for converting numbers in a file to corresponding words

import java.io.*;
import java.lang.*;

class NumToWords
{
public static void main(String a[]) throws IOException
{
String s="";
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter filename : ");
try
{
s=br.readLine();
}catch(Exception e){}
InputStream in=new FileInputStream(s);
MyInputStream mis=new MyInputStream(in);
mis.changeNumbers();
in.close();
mis.close();
}
}
class MyInputStream extends FilterInputStream
{
InputStream is;
MyInputStream(InputStream in)
{
super(in);
is=in;
}
public void changeNumbers() throws IOException
{
PushbackInputStream pis;
String num="";
char ch;
int c;
pis=new PushbackInputStream(is);
while((c=pis.read())!=-1)
{
ch=(char)c;
if('0'<=ch&&ch<='9')
{
num="";
while('0'<=ch&&ch<='9'&&c!=-1)
{
num=num+ch;
c=pis.read();
ch=(char)c;
}
System.out.print(MyInputStream.process(num));
pis.unread(ch);
}
else
System.out.print(ch);
}
}
static String process(String str)
{
String a1[]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
String a2[]={"Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
String a3[]={"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
String a4[]={"Hundered","Thousand","Lakhs","Crores"};
int num=0;
try
{
num=Integer.parseInt(str);
}catch(Exception e){}
if(num==0)
return "Zero";
int n,n1;
String ans="";
String ans1="";
n1=num%10;
num=num/10;
if(n1!=0)
ans=a1[n1-1];
if(num>0)
{
n=num%10;
num=num/10;
if(n==1)
ans=a3[n1];
else if(n!=0)
ans=a2[n-2]+" "+ans;
}
if(num>0)
{
n=num%10;
num=num/10;
if(n!=0)
ans=a1[n-1]+" "+a4[0]+" "+ans;
}
for(int i=1;num>0;i++)
{
n1=num%10;
num=num/10;
if(n1!=0)
ans1=a1[n1-1];
if(num>0)
{
n=num%10;
num=num/10;
if(n==1)
ans1=a3[n1];
else if(n!=0)
ans1=a2[n-2]+" "+ans1;
}
ans=ans1+" "+a4[i]+" "+ans;
ans1="";
}
return(ans);
}
}

Program to Find Maximum of 2 nos. In JAVA

class Maxof2
{

public static void main(String args[]){

//taking value as command line argument.

//Converting String format to Integer value

int i = Integer.parseInt(args[0]);

int j = Integer.parseInt(args[1]);

if(i > j)

System.out.println(i+" is greater than "+j);

else

System.out.println(j+" is greater than "+i);

}

}

Program for counting no. of Chars, Words and Lines in a file

import java.lang.*;
import java.io.*;
import java.util.*;
class WordCount
{
public static void main(String arg[]) throws Exception
{
int char_count=0;
int word_count=0;
int line_count=0;
String s;
StringTokenizer st;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter filename : ");
s=buf.readLine();
buf=new BufferedReader(new FileReader(s));
while((s=buf.readLine())!=null)
{
line_count++;
st=new StringTokenizer(s," ,;:.");
while(st.hasMoreTokens())
{
word_count++;
s=st.nextToken();
char_count+=s.length();
}
}
System.out.println("Character Count : "+char_count);
System.out.println("Word Count : "+word_count);
System.out.println("Line Count : "+line_count);
buf.close();
}
}

We Are Founder..