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 :: how to check if notification is showing in android 
Java :: java string to integer 
Java :: queue in java 
Java :: Java push() Method 
Java :: how to create localdate object in java 
Java :: java run cmd 
Java :: which api is android 12 
Java :: write files with FileOutPutStream java 
Java :: Converting String Array to an Integer Array 
Java :: variables java 
Java :: java printf tab 
Java :: java substring after last char 
Java :: processing angle between two points 
Java :: mapping over a list of promises in javaascript 
Java :: java object to int 
Java :: loop through java object 
Java :: insertion sort in java 
Java :: install java using cmd 
Java :: java program to find the power of a number 
Java :: greater than sign in java 
Java :: linear search algorithm java 
Java :: rock paper scissor in java 
Java :: java stream and filter 
Java :: get list data in java 
Java :: the main of java 
Java :: java_remove last char 
Java :: infinite for loop java example 
Java :: convert arraylist to array int 
Java :: -3 to string in java 
Java :: add to list java 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =