Write a Java Program to sort the numbers?


/* Java Program to sort the numbers */
public class SortNumbers {

     public static void main(String[] args) {      
         int[] number = {23,45,36,44,90}; /* give in put array here*/
         int temp;
         for (int i =0; i<number.length ; ++i){
             for (int j = i + 1; j < number.length; ++j){
                 if (number[i] > number[j]){
                     temp =  number[i];
                     number[i] = number[j];
                     number[j] = temp;
                 }
             }
         }      
         System.out.println("Sotered array : ");
         for(int i=0; i<number.length;i++){
                System.out.print(number[i]+ " ");
         }            
     }
}

Sort Numbers

Write a Java program to print the numbers in diamond pattern?


/* Q. Write a Java Program to print the Numbers in Diamond pattern? */
public class NumbersInDiamond {
     public static void main(String[] args) {
           int rows = 9; /* give input here*/       
           for (int i = 1; i <= rows; i++) {
                int number = 1;
                System.out.format("%"+ (rows-i+1)*2+"s","");
                for (int j = 1; j <= i; j++) {
                     System.out.format("%4d",number++);   
                }
                System.out.println();
           }
           for (int i = rows-1; i >0 ; i--) {
                int number = 1;
                System.out.format("%"+ (rows-i+1)*2+"s","");
                for (int j = 1; j <= i; j++) {
                     System.out.format("%4d",number++);
                } 
                System.out.println();
           }         
      }
}

Diamond Pattern

Write a Java program to print the numbers in pyramid format?


/*Q. Write a Java Program to Print the Numbers in Pyramid format?*/
public class PyramidNumbers {
     public static void main(String[] args) {
           int rows = 11; /* give input here*/        
           for (int i = 1; i <= rows; i++) {
                int number = 1;
                System.out.format("%"+ (rows-i+1)*2+"s","");
                for (int j = 1; j <= i; j++) {
                      System.out.format("%4d",number++);   
                }
                System.out.println();
           }
     }
 }

Pyramid Pattern

Write a Java program to print the numbers in triangle format?


/*Q. Write a Program to print the Numbers in Triangle format?*/
public class NumbersInTriangle {
     public static void main(String[] args) {
           int rows = 10; /* give input here*/         
           for (int i = 1; i <= rows; i++) {
                int number = 1;
                for (int j = 1; j <= i; j++) {
                     System.out.format("%2d",number++);                   
                }
                System.out.println();
           }
     }
}

Triangle Format

Write a Java program to print pascal triangle


/* Q. Write a Java Program to print Pascal Triangle */
public class PascalTriangle {
     public static void main(String[] args) {
            int rows = 10; /* give input here*/
            for (int i = 0; i < rows; i++) {
                 int number = 1;
                 System.out.format("%" + (rows - i) * 2 + "s", ""); 
                /* to keep distance from initial*/
                 for (int j = 1; j <= i; j++) {
                      System.out.format("%4d", number);
                      number = number * (i - j) /j;
                 }
                 System.out.println();
            }
      }
}

Pascal Triangle

Write a Java program to check whether given string is palindrome or not?


/*Q. Java Program to Check whether GivenString is palindrome or not  */
public class PolindromeString {
     public static void main(String[] args) {
           String str = "aba"; /* give input String here */
           String rev="";
           int length = str.length();
           for (int i = length - 1; i >= 0; i--) {      
                rev = rev + str.charAt(i);
           }
           if(rev.equals(str)){
                System.out.println("Given String is Polindrome");
           }
           else{
                System.out.println("Given String is not polindrome");
           }
     }

}

Palindrome Number

Write a Java Program to Check whether GivenString is palindrome or not


/*Q. Java Program to Check whether GivenString is palindrome or not  */
public class PolindromeString {
     public static void main(String[] args) {
           String str = "aba"; /* give input String here */
           String rev="";
           int length = str.length();
           for (int i = length - 1; i >= 0; i--) {      
                rev = rev + str.charAt(i);
           }
           if(rev.equals(str)){
                System.out.println("Given String is Polindrome");
           }
           else{
                System.out.println("Given String is not polindrome");
           }
     }

}

Palindrome String

Write a JAVA program to reverse the string?


/*JAVA Program to reverse the String */
public class ReverseString {
     public static void main(String[] args) {
           String str = "abcdef"; /* give input String here */
           String rev="";     
           int length = str.length();
           for (int i = length - 1; i >= 0; i--) {
                rev = rev + str.charAt(i);
           }
           System.out.println("Given  String  : "+str);
           System.out.println("Reverse String : "+rev);
     }

}

Reverse the String

Write a Java program to reverse the given number ?


/* Java Program to reverse the Given Number */
public class ReverseNumber {
    public static void main(String[] args) {
        int number = 321; /* give input here */
        int rev = 0;
        int num = number;
        while (num > 0) {
             int rem = num % 10;
             rev = rev*10+ rem;
             num /= 10;
        }
        System.out.println("Reverse Of Given Number is : "+rev);
    }
}

Reverse Number

Write a java program to find second maximum?

/* Java Program to find second maximum number*/ 
public class SecondMaximum {
     public static void main(String[] args) {         
           int[] array = {1,2,34,156,436,3};/* give input here*/ 
           int firstMax = 0;
           int secondMax= 0;          
           for(int i = 0; i<array.length;i++){
                if(firstMax < array[i]){
                     secondMax = firstMax;
                     firstMax = array[i];
                }
           }
           System.out.println("First Max Number: "+firstMax);
           System.out.println("Second Max Number: "+secondMax);
     }

}

Second Maximum

Write a Java program to find the Maximum number?


/* Write a Java Program to find the Maximum Number */
public class Maximum {
     public static void main(String[] args) {
           int[] array = {1,2,34,56,436,3};/* give input here*/
           int Maximum = array[0];       
           for(int i = 0; i<array.length;i++){
                if(Maximum < array[i]){
                     Maximum = array[i];
                }
           }
           System.out.println("Max Number: "+Maximum);
     }
}

Maximum Number

Write a Java program to find Armstrong number?


/*Java Program to find armstrong number*/
public class ArmStrongNumber {
     public static void main(String[] args) {        
           int num = 153; /* Give input here*/
           int rem,sum =0;
           int n=num;
           while(num > 0 ){
                 rem = num % 10;
                 sum = sum+rem*rem*rem;
                 num = num/10;
           }
           if(sum == n){
                System.out.println("Given Number is ArmStrongNumber");
           }
           else{
                System.out.println("Not ArmStrongNumber");
           }
          
     }
}

Armstrong Number

Write a Java program to convert binary to decimal?


/* Java Program to convert binary to decimal*/
public class BinaryToDecimal {
     public static void main(String a[]){
           int binary = 111; /* give required binary number here */
           int decimal = 0;
           int power = 0;
           while (binary > 0){
                int reminder = binary % 10;
                decimal += reminder * Math.pow(2, power);
                binary = binary / 10;
                power++;
           }
           System.out.println("required Decimal Number : "+decimal);
     }
}

Binary to decimal

Write a Java program to print number from decimal to binary


/*Java Program to print number from Decimal to Binary*/
public class DecimalToBinary {
    public static void main(String a[]){      
        int num = 5;  /*give required number here*/
        int binary[] = new int[25];
        int index = 0;
         while( num > 0){
             binary[index++] = num%2;
             num = num/2;
         }
         /* print in reverse order*/
         for(int i = index-1; i>=0; i--){
            System.out.print(binary[i]);
         }    
    }
}

Decimal to Binary

Write a Java program to find the Fibonacci series


/*Java Program to find the FibonacciSeries */
public class FibonacciSeries {
   public static void main(String a[]){   
         int limit = 15; /* give limit here */
         int[] feb = new int[limit];
         feb[0] = 0;
         feb[1] = 1;
   /* store all elements in array feb[] */
         for(int i=2; i < limit; i++){
             feb[i] = feb[i-1] + feb[i-2];
         }
    /* print all array elements */
         for(int i=0; i< limit; i++){
                 System.out.print(feb[i] + " ");
         }
    }
}

Fibanacci Series

Write a Java program to find the sum of digits?


/*Java Program to find the sum of digits */
public class SumOfDigits{

     public static void main(String args[]) {
           int number = 333;
           int sum = 0;
           int num = number;
           while (num > 0) {
                int lastDigit = num % 10;
                sum += lastDigit;
                num /= 10;
           }
           System.out.println("Sum of digits : "+sum);
     }
}

Sum Of Digits