Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Diamond pattern program in java

// Diamond pattern - TutorialsTonight

public class diamond {
  public static void main(String[] args) {
    int size = 5;
    // upside pyramid
    for (int i = 1; i <= size; i++) {
      // printing spaces
      for (int j = size; j > i; j--) {
        System.out.print(" ");
      }
      // printing star
      for (int k = 0; k < i * 2 - 1; k++) {
        System.out.print("*");
      }
      System.out.println();
    }
    // downside pyramid
    for (int i = 1; i <= size - 1; i++) {
      // printing spaces
      for (int j = 0; j < i; j++) {
        System.out.print(" ");
      }
      // printing star
      for (int k = (size - i) * 2 - 1; k > 0; k--) {
        System.out.print("*");
      }
      System.out.println();
    }
  }
}

/* Output:

    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
*/
Comment

Diamond star pattern in java

class diamond {
  public static void main(String[] args) {
    int size = 5;
    // upside pyramid
    for (int i = 1; i <= size; i++) {
      // printing spaces
      for (int j = size; j > i; j--) {
        System.out.print(" ");
      }
      // printing star
      for (int k = 0; k < i * 2 - 1; k++) {
        System.out.print("*");
      }
      System.out.println();
    }
    // downside pyramid
    for (int i = 1; i <= size - 1; i++) {
      // printing spaces
      for (int j = 0; j < i; j++) {
        System.out.print(" ");
      }
      // printing star
      for (int k = (size - i) * 2 - 1; k > 0; k--) {
        System.out.print("*");
      }
      System.out.println();
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: HttpServer example java 
Java :: h2 database spring boot 
Java :: java output array lists to file 
Java :: how to compare current date and time with another date and time in android 
Java :: java file system append new line 
Java :: convert string to character array 
Java :: calling method in java 
Java :: how to call intent in adapter class in android 
Java :: wait random time java 
Java :: how to check the lines in a file java scanner 
Java :: java how to check string is number 
Java :: java selenium implicitly wait 
Java :: select in selenium java 
Java :: java flowlayout 
Java :: split string 2 characters java 
Java :: how to use random bound on doubles java 
Java :: how to add two numbers in java 
Java :: try block in java 
Java :: java numbers 
Java :: java thread dump 
Java :: materialbutton remove shadow xml 
Java :: string to char in java 
Java :: java convert java.util.Date to LocalDate 
Java :: create new empty list java 
Java :: java string to float 
Java :: find minimum in rotated sorted array 
Java :: how to change theme of app in android studio programmatically 
Java :: java arraylist deep copy 
Java :: has a relationship in java 
Java :: hashmap to list java 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =