Tuesday, August 18, 2009

java code to hear Beep sound,Press any single Digit

import java.util.*;
public class Beep{


public static void main(String[] args) {

if(args[0].equals("1"))
System.out.println("\007");
if(args[0].equals("2"))
System.out.println("\007\007");
if(args[0].equals("3"))
System.out.println("\007\007\007");
if(args[0].equals("4"))
System.out.println("\007\007\007\007");
if(args[0].equals("5"))
System.out.println("\007\007\007\007\007");
if(args[0].equals("6"))
System.out.println("\007\007\007\007\007\007");
if(args[0].equals("7"))
System.out.println("\007\007\007\007\007\007\007");
if(args[0].equals("8"))
System.out.println("\007\007\007\007\007\007\007\007");
}

}

Thursday, March 26, 2009

java code to print a word in Double Quotes

import java.io.*;
public class names
{
public static void main(String [] x)throws IOException
{
System.out.println("Enter the name");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String w=br.readLine();

System.out.println("\""+w+"\"");

}
}

java code to prtint a pattern

public class patternz
{
public static void main(String[] u)
{
for(int i=1;i<=20;i++)
{
for(int sp=20;sp>i;sp--)
{
System.out.print(" ");
}
for(int j=1;j{
System.out.print("* ");
}
System.out.println();
}
}

}

java code to find prime numbers

import java.io.*;
public class prime
{
public static void main(String [] y)
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number.. ");
String x=null;
boolean b=true;
try
{
 x=br.readLine();
}
catch(IOException io)
{
System.out.println(io);
}
int z=Integer.parseInt(x);
for(int i =2;i<=Math.sqrt(z);i++)
{
if(z%i==0)
b=false;
}
if(b==true)
System.out.println("number is prime "+z);
else
System.out.println("number is not prime "+z);
}
}

java code to reverse a String

import java.io.*;
public class reverse1
{
public static void main(String [] x)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Number");
Integer i=new Integer(br.readLine());
String ip=i.toString();
StringBuffer sf=new StringBuffer(ip);
String z=sf.reverse().toString();
System.out.println(z);
if(ip.equals(z))
System.out.println(" The Number "+ip+" is a palindrome");
else
System.out.println(" The Number "+ip+" is not a palindrome");

}
}

Left shift and right shift usig java

public class Shift
{
public static void main(String [] x)
{
int c=5;
System.out.println("After Left Shifting 5 by 2 points "+(c<<2 ));
System.out.println("After Right Shifting 5 by 2 points "+(c>>2 ));

}
}

Alphabatical table using arrays

import java.util.Arrays;
public class testarrays
{
public static void main(String [] x)
{
char [] array1=new char[26];
for (int i = 'A' ,j=0;i<='Z';i++,j++)
array1[j]=(char)i;
System.out.println(Arrays.toString(array1));
}
}

java code for TestBanking

import java.io.*;
class Bank
{
Customer customers[];
int noOfcustomers;
public Bank()
{
customers = new Customer[20];
noOfcustomers=0;
}

public void addcustomer(String name)
{
int i=noOfcustomers++;
 customers[i]= new Customer(name);
}

public int getNumOfcustomers()
{
return noOfcustomers;
}
public Customer getCustomer(int customer_index)
{
return customers[customer_index-1];
}
}

 class Customer
{
String name;
public String toString()
{
return(name);
}

public Customer(String n )
{
name=n;
}
}

class Testbanking
{
public String acceptDetails() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println();
System.out.println("Enter the first name of customer");
String x=br.readLine();
System.out.println();
System.out.println();
System.out.println("Enter the second name of customer");
String y=br.readLine();
return (x+" "+y);
}
public static void main(String [] arr)throws IOException
{
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
Bank b = new Bank();
Testbanking tb=new Testbanking();
String choice;
do
{
b.addcustomer(tb.acceptDetails());
int number= b.getNumOfcustomers();
System.out.println("No of customers in the bank = "+number);
System.out.println();
for(int i=1;i<=number;i++)
System.out.println(b.getCustomer(i));
System.out.println();
System.out.println("Continue? Y/N");
choice=br1.readLine();
}
while(choice.toUpperCase().equals("Y"));
}
}

Thursday, February 26, 2009

java code to find volume of a cube

public class Volumecube
{
public static void main(String [] s)
{
int j=Integer.parseInt(s[0]);
int vol;
vol=j*j*j;
System.out.println();
System.out.println("The volume of cube of side "+s[0]+" is"+" "+ vol);
}
}

Wednesday, February 25, 2009

Sample java code for Calculator

import java.io.*;
public class Calculus
{
public static void main(String []w) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter The First Integer :- ");
String x=br.readLine();
int y=Integer.parseInt(x);
System.out.println();
System.out.print("Enter The Second Integer:- ");
x=br.readLine();
int z=Integer.parseInt(x);
System.out.println();
System.out.println("Enter Your Choice");
System.out.println();
System.out.println("1.Addition");
System.out.println("2.Substraction");
System.out.println("3.Multiplication");
System.out.println("4.Division");

x=br.readLine();
int choice=Integer.parseInt(x);

switch (choice)
{
case 1:
System.out.println(y+"+"+z+"="+(y+z));
break;

case 2:
System.out.println(y+"-"+z+"="+(y-z));
break;

case 3:
System.out.println(y+"x"+z+"="+(y*z));
break;

case 4:
System.out.println(y+"/"+z+"="+(y/z));
break;

default:System.out.println("Enter listed choices....");

}


}
}

Sunday, January 11, 2009

राजू नारायणा स्वामी IAS

By-Krishnakumar-Dubai

A Very intersting topic on Raju Narayanaswamy.


Pls Read this article and think about RAJU NARAYANASWAMY IAS first Rank
in State in Secondary School Examination First Rank in University in
Plus Two First Rank in IIT Entrance Examination
First Rank in All India IIT Computer Science First Rank in IAS Entrance
Examination
First Rank in IAS Training Institute

On passing out from IIT Chennai Mr. Narayanaswamy was offered
scholarship by the prestigious Massachusetts Institute of Technology ,
USA . He who came from a middle class family believed that he had a
moral obligation to give something in return for the lakhs of rupees
the government spent on him as an IIT student. He had the intelligence
and conviction to realize that this money came also from the poorest of
the poor - who pay up the excise duty on textiles when they buy cloth,
who pay up customs, excise and sales tax on diesel when they travel in a
bus, and in numerous other ways indirectly pay the government. So he
decided to join IAS hoping he could do something for the people of this
country. How many young men have the will power to resist such an offer
from USA ? Narayanaswamy did never look at IAS as a black money spinner
as his later life bears testimony to this fact.

After a decade of meritorious service in IAS, today, Narayanaswamy is
being forced out of the IAS profession. Do you know why?

A real estate agent wanted to fill up a paddy field which is banned
under law. An application came up before Narayanaswamy who was sub
collector the, for an exemption from this rule for this plot of land.
Upon visiting the site he found that the complaint from 60 poor families
that they will face water logging due to the waste water from a nearby
Government Medical College if this paddy field was filled up was
correct. Narayanswamy came under intense political pressure but he did
what was right - refused permission for filling up the paddy field.
That was his first confrontation with politicians.

Soon after his marriage his father-in-law closed down a public road to
build compound wall for his plot of land. People approached
Narayanaswamy with complaint.


When talking with his own father-in-law did not help, he removed the
obstructing wall with police help. The result, his marriage broke up.

As district Collector he raided the house of a liquor baron who had
defaulted Rupees 11 crores payment to government and carried out revenue
recovery. A Minister directly telephoned him and ordered to return the
forfeited articles to the house of the liquor baron.
Narayanswamy politely replied that it is difficult. The minister replied
that Narayanaswamy will suffer.
In his district it was a practice to collect crores of rupees for
earthen bunds meant for poor farmers, but which were never constructed.
A bill for rupees 8 crores came up before Narayanaswamy.
He inspected the bund. He found it very weak and said that he will pass
the bill after the rainy season to ensure that the bund served the
purpose.
As expected the earthen bund was too weak to stand the rain and it
disappeared in the rain. But he created a lot of enemies for saving 8
crores public money. The net result of all such unholy activities was
that he was asked to go on leave by the government. Later such an
illustrious officer was posted as "State Co-Ordinator, Quality
Improvement Programme for Schools". This is what the politician will do
to a honest officer with backbone - post him in the most powerless
position to teach him a lesson. Since he found that nothing can be
achieved for the people if he continued with the State Service he opted
for central service. But that too was denied on some technical ground.

What will you do when you have a brilliant computer career anywhere in
the world you choose with the backing of several advanced technical
papers too published in international journals to your credit?

When you are powerless to do anything for the people, why should you
waste your life as the Co-Ordinator for a Schools Programme?

Mr. Narayanaswamy is on the verge of leaving IAS to go to Paris to take
up a well paid United Nations assignment. The politicians can laugh
thinking another obstacle has been removed. But it is the helpless
people of this country who will lose - not Narayanaswamy. But you have
the power to support capable and honest bureaucra ts like Narayaswamy,
G.R.Khairnar and Alphons Kannamthanam who have suffered a lot under self
seeking politicians who rule us. You have even the power to replace such
politicians with these kind of people dedicated to the country. The
question is will you do the little you can do NOW? At least a vote or
word in support of such personalities?

Please pass on this mail to your friends " There is a difference
between an objective and actions. Unless you understand your objective,
you will be wasting your time in actions.
Know your objective first " - Swami Vivekananda


Regards