Program to reverse the number

package javabox;

public class ReverseNumberExample {

    public static void main(String[] args) {

        int n = 1234, s = 0;

  while(n>0){    
   r=n%10;  //getting remainder  
   s=(s*10)+r;    
   n=n/10;    
  }    

        System.out.println("Reversed Number: " + s);
    }
}

Output - 
Reversed Number: 4321

Program to check Armstrong number

 Armstrong number is a number that is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371, 407 etc.  Let's say, 153 = (1*1*1)+(5*5*5)+(3*3*3)  


package javabox;

class ArmstrongExample{  

  public static void main(String[] args)  {  
  
    int c=0,a,temp;  
    int n=153; //Number to check armstrong  
    temp=n;  
    while(n>0)  
    {  
    a=n%10;  
    n=n/10;  
    c=c+(a*a*a);  
    }  
    if(temp==c)  
    System.out.println("Armstrong number");   
    else  
        System.out.println("Not Armstrong number");   
   }  

}  

Output - 
Armstrong number

Program to find Factorial using Recursion

Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!. For example: 4! = 4*3*2*1 = 24  

package javabox;

class FactorialExample{  

 static int factorial(int n){    
  if (n == 0)    
    return 1;    
  else    
    return(n * factorial(n-1));    
 }    
 public static void main(String args[]){  

  int i,fact=1;  
  int number=4;//Number to calculate factorial    
  fact = factorial(number);   
  System.out.println("Factorial of "+number+" is: "+fact);    
 }  
}  

Output - 

Factorial of 4 is: 24

Program to find Factorial using loop

Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!. For example: 4! = 4*3*2*1 = 24  


package javabox;

class FactorialExample{  

 public static void main(String args[]){  

  int i,fact=1;  
  int number=5;//It is the number to calculate factorial    
  for(i=1;i<=number;i++){    
      fact=fact*i;    
  }    
  System.out.println("Factorial of "+number+" is: "+fact);    
 }  

}  


Output - 
Factorial of 4 is: 24

Program to check Palindrome number

palindrome number is a number that is same after reverse. For example 545, 151, 34543, 343, 171, 48984

package javabox;

class PalindromeExample{  

 public static void main(String args[]){
  
  int r,sum=0,temp;    
  int n=454; //Number to be checked for palindrome  
  
  temp=n;    
  while(n>0){    
   r=n%10;  //getting remainder  
   sum=(sum*10)+r;    
   n=n/10;    
  }    
  if(temp==sum)    
   System.out.println("Palindrome number ");    
  else    
   System.out.println("Not palindrome");    
}  
}  


Output - 
Palindrome number

Program to swap number with temporary variable

package javabox;

public class SwapExample {


public static void main(String a[]){

int x = 30;
int y = 40;
int temp;
System.out.println("Before swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
temp = x;
x = y;
y = temp;
System.out.println("After swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
}
}

Output -

Before swap:
x value: 30
y value: 40
After swap:
x value: 40
y value: 30

Program to swap number without temporary variable

package javabox;

public class SwapExample {

public static void main(String a[]){
int x = 30;
int y = 40;
System.out.println("Before swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
x = x+y;
y = x-y;
x = x-y;
System.out.println("After swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
}
}

Output -
Before swap:
x value: 30
y value: 40
After swap:
x value: 40
y value: 30

Basic structure and printing elements of Linked list in java

class Node {      int data ;      Node next ;           Node ( int data ){            this . data = data ;            ...