Reset
Diamond Pattern
Program Info
Program Code
×

Diamond Pattern

We are printing diamond pattern.

Footer

×

Diamond Pattern

import java.util.Scanner;

public class Print_Diamond_Pattern {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int n = scan.nextInt();
        int nsp=n-1, nst=1;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= nsp; j++) {
                System.out.print("  ");
            }

            for (int k = 1; k <= nst; k++) {
                System.out.print("* ");
            }
            nsp--;
            nst +=2;
            System.out.println();
        }

        nsp=1; 
        nst=2*n-3;
        for (int i = 1; i <= n-1; i++) {
            for (int j = 1; j <= nsp; j++) {
                System.out.print("  ");
            }

            for (int k = 1; k <= nst; k++) {
                System.out.print("* ");
            }
            nsp++;
            nst -=2;
            System.out.println();
        }

        scan.close();
    }
}

Footer

Hollow Star Rectangle Pattern
Program Info
Program Code
×

Hollow Star Rectangle Pattern

We are printing hollow star rectangle pattern.

Footer

×

Hollow Star Rectangle Pattern

import java.util.Scanner;

public class Print_Hollow_Star_Rectangle_Pattern {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        System.out.print("Enter number of rows: ");
        int row = scan.nextInt();

        System.out.print("Enter number of columns: ");
        int col = scan.nextInt();

        for (int i = 1; i <= row; i++) {
            for (int j = 1; j <= col; j++) {
                if(i == 1 || i == row || j == 1 || j == col) {
                    System.out.print("* ");
                } else {
                     System.out.print("  ");
                }
                
            }
            System.out.println();
        }

        scan.close();
    }
}

Footer

Number Pyramid Pattern
Program Info
Program Code
×

Number Pyramid Pattern

We are printing number pyramid pattern.

Footer

×

Number Pyramid Pattern

import java.util.Scanner;

public class Print_Number_Pyramid_Pattern {
   public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int n = scan.nextInt();

        for(int i=1; i<=n; i++) {
           //spaces
           for(int j=1; j<=n-i; j++) {
               System.out.print(" ");
           }

           //numbers
           for(int j=1; j<=i; j++) {
               System.out.print(i+" ");
           }
           System.out.println();
        }

        scan.close();
   }   
}

Footer

Palindromic Pyramid Pattern
Program Info
Program Code
×

Palindromic Pyramid Pattern

We are printing palindromic pyramid pattern.

Footer

×

Palindromic Pyramid Pattern

import java.util.Scanner;

public class Print_Palindromic_Pyramid_Pattern {
   public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int n = scan.nextInt();

        for(int i=1; i<=n; i++) {
           //spaces
           for(int j=1; j<=n-i; j++) {
               System.out.print(" ");
           }

           //first part
           for(int j=i; j>=1; j--) {
               System.out.print(j);
           }

           //second part
           for(int j=2; j<=i; j++) {
               System.out.print(j);
           }
           System.out.println();
        }

        scan.close();
   }   
}

Footer

Pyramid Pattern
Program Info
Program Code
×

Pyramid Pattern

We are printing pyramid pattern.

Footer

×

Pyramid Pattern

import java.util.Scanner;

public class Print_Pyramid_Pattern_2 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int n = scan.nextInt();
        int nsp=n-1, nst=1;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= nsp; j++) {
                System.out.print("  ");
            }

            for (int k = 1; k <= nst; k++) {
                System.out.print("* ");
            }
            nsp--;
            nst +=2;
            System.out.println();
        }

        scan.close();
    }
}

Footer

Rhombus Pattern
Program Info
Program Code
×

Rhombus Pattern

We are printing rhombus pattern

Footer

×

Rhombus Pattern

import java.util.Scanner;

public class Print_Rhombus_Pattern {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int n = scan.nextInt();

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n-i; j++) {
                System.out.print("  ");
            }

            for (int k = 1; k <= n; k++) {
                System.out.print("* ");
            }
            System.out.println();
        }

        scan.close();
    }
}

Footer

Sort Array
Program Info
Program Code
×

Sort Array

We are doing sort an array with the help of Bubble Sort Algorithm.

Footer

×

Sort Array

import java.util.Scanner;

public class Sort_Array_Using_Bubble_Sorting_Algorithm {

    public static void bubbleSort(int[] arr) {
        int n = arr.length;
         for(int i=0;i<n-1;i++){
            for(int j=0;j<n-1-i;j++){
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }

    public static void print(int[] arr) {
         for(int ele : arr){
            System.out.print(ele+" ");
         }
         System.out.println();
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        // First array input
        System.out.print("Enter size of array: ");
        int n = sc.nextInt();
        int[] arr = new int[n];

        System.out.println("Enter elements of array:");
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        System.out.println("Array Before sorted :");
        print(arr);
        bubbleSort(arr);
        System.out.println("Array after sorted :");
        print(arr);

        
    }

}

Footer

Showing page  1  of  1  (Total  7 records)
×
Name : Krishna Verma    |    Father's Name : Mr. Satish Kumar    |    Email ID : krishnaverma28081997@gmail.com    |    Religion : Hindu    |    Address : Dayampur, kanker khera, Meerut Cantt (250001), UP    |    Date of Birth : 28 August 1997    |    Marital Status : Non-Married    |    Place of Birth : Dayampur Kanker Khera Meerut Cantt.    |    Gender : Male    |    Age : 28    |    Contact : 9520335394    |    Father's Occupation : Sports man    |    Mother's Name : Smt. Kuntesh Devi    |    Mother's Occupation : Homemaker    |    Number of Brothers : 1    |    Number of Sisters : 1    |    Current Residence : Dayampur kanker khera meerut cantt    |    Family Type : Nuclear Family    |    Family Name : verma    |    Height : 5' 6"    |    Weight : 70 kg    |    Complexion : Fair    |    Body Type : Athletic    |    Hair Color : Black    |    Health Status : Good    |    Any Physical Disability : No    |    Highest Qualification : B.Tech (CSE)    |    Master Skill : PHP Laravel    |    Total Projects : 40 +    |    Total Skills : 25 +    |    Languages Known : Hindi and English    |    Website : krishnaportfolio.in    |    Siblings : 3    |    Nationality : Indian    |    Total Experience : 5 Years    |    LinkedIn : https://www.linkedin.com/in/krishna-verma-840b71356/    |    Total Programs : 10000    |    Total Projects : 40    |    Total Skills : 25    |    Total Experience : 5    |    Total DSA Problems : 200    |    Total Served Companies : 2    |    Leetcode : https://leetcode.com/u/krishnavermadeveloper/    |    Naukri : https://www.naukri.com/mnjuser/profile?id=&altresid