.

Friday, 27 March 2015

Swapping two variables with using third variable in JAVA

class swap
{
   public static void main(String []args)
   {
      int a=25;
      int b=10;
      System.out.println("Intially a="+a+"b="+b);
      a=a+b;
      b=a-b;
      a=a-b;
      System.out.println("a="+a+"\nb="+b);
   }
}
Read more ...

Program to find factorial in JAVA



class factorial{

public static void main(String args[])

{

int f=1,i;

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

f=f*i;

System.out.println("factorial="+f);

}

}
Read more ...

Program to set and print employee details

class Details

int empid,deptid,salary;

//method to set details
void setEmployeeDetails()
{
empid=10002;
deptid=15;
salary=5000;
}

//method to print details
void printEmployeeDetails()
    {
System.out.println(empid);
System.out.println(deptid);
System.out.println(salary);
      }

}

//main class
class employee
{
public static void main(String[] args)
{

//method to create object of detail class

details ob=new details();

//method to call the function through object

ob.printEmployeeDetails();
}
}
Read more ...

Prime number program in JAVA

Program to find prime number in java

class prime{
public static void main(String []args){
int num=6;
int fac=0;
for(int i=1;i<=6;i++)
{
 if(num%i==0)
   fac++;
}
if(fac==2)
System.out.println("Is a prime no");
else
 System.out.println("Not a prime no");
}
}
Read more ...

Fibonacci program in JAVA

Program to find fibonacci series in JAVA

class fib
 {
 public static void main(String[] arg)
 {
  int i,a=0,b=0,c=1;
  int n=8;
   System.out.println("fibonacci series"+n);
  for(i=1;i<=n;i++)
  {
   a=b;
  b=c;
  c=a+b;
  System.out.println(c);
  
  }
  }
  }
        
Read more ...

Finding five armstrong numbers in JAVA

Program to find Five armstrong Numbers in java

class fivearms
{
public static void main(String args[])
{
int r,temp,count;
for(count=1;count<500;count++)
{
int sum=0;
temp=count;
while(temp!=0)
{
r=temp%10;
temp=temp/10;
sum=sum+(r*r*r);
}
if(sum==count)
System.out.println("no.s are"+count);}
}
}
Read more ...

"Hello World" program in JAVA

Steps to develop a hello world program in java-


class Hello {
//Everything should be written inside this block
public static void main(String args[])
{

//to print on the console
 System.out.println("hellow world");

}
}

1. Everything in the world is defined in terms of class.If you want to go for developing car first you will design the model for it. In Every car everything will be same as the model but objects can hold different characterstics(objects are real world entities in case of car it can be Honda city, Tata nano, swift desire)

Class- class is nothing but a blueprint of an object.

System.out.println("") is a method to print anything inside the parameter on the console.where System is a class, out is its object and println() is a method of it.






Read more ...