Tuesday, March 18, 2008

split of a 4 digit number

/* Program to split of a 4 digit number */

class P7
{
public static void main(String args[])
{
int x = 1234, y, z;

y = x /1000 ;
System.out.println(" The digit in the Thousand's place = "+y);

z = x % 1000;
y = z /100;
System.out.println("\n The digit in the Hundred's place = "+y);

z = z % 100;
y = z / 10;
System.out.println("\n The digit in the Ten's place = "+y);

y = z % 10;
System.out.println("\n The digit in the Unit's place = "+y);

}
}

converts inches to centimeters

/* Program to converts inches to centimeters */

class P6
{
public static void main(String args[])
{
float inches = 16.9F, cm ;
cm = 2.54F * inches ;
System.out.println(""+inches+" inches = "+ cm +" centimeters");

}
}

calculate the simple interest

/* Program to calculate the simple interest */

class P5
{
public static void main(String args[])
{
float principle, no_of_years, rate_of_interest, simple_interest;
principle = 10000;
no_of_years= 6;
rate_of_interest = 8.5F;
simple_interest = principle * no_of_years * rate_of_interest ;
simple_interest = simple_interest / 100 ;
System.out.println("\n Simple Interest on a principle of "+principle+" is "+simple_interest+" at the rate of "+rate_of_interest+" for a period of "+no_of_years);

}
}

computing the volume of a sphere

/* Program for computing the volume of a sphere */

class P4
{
public static void main(String args[])
{
float r=2, volume, pi = 3.14152F;

volume = (4 * pi * r * r * r) / 3 ;
System.out.println("Volume : "+volume);
}
}

interchange the value of the given 2 numbers

/* Program to interchange the value of the given 2 numbers */

class P3
{

public static void main(String args[])
{
int no1=5, no2=18, temp;

System.out.println("\nBefore interchange Numbers are : ");
System.out.println("First Number : "+no1);
System.out.println("Second Number : "+no2);

temp = no1;
no1 = no2;
no2 = temp;

System.out.println("\nAfter interchange Numbers are : ");
System.out.println("First Number : "+no1);
System.out.println("Second Number : "+no2);

}
}

Square and cube of a Number

/* Program to find Square and cube of a Number */

class P2
{

public static void main(String args[])
{
int i=5 ;

System.out.println(" The Number is : "+i) ;
System.out.println("The Square of Number is : "+(i*i));
System.out.println("The Cube of Number is : "+(i * i* i));

}
}

convert Rs. into paise

/* Program to convert Rs. into paise */

class P17
{
public static void main(String args[])
{
double rs=75.95;
double paise1,paise2;

paise1= rs*100;
System.out.println("Rs."+rs+" = "+(long)paise1+" paise");

rs= 18.75;
paise2= rs*100;
System.out.println("Rs."+rs+" = "+(long)paise2+" paise");

}
}