Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ow222ea_assign2;
- import java.util.Scanner;
- public class Diamonds {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Give a postive number: ");
- int number = input.nextInt();
- int startandfinishspaces = number -1;
- int firstlinestar = 1;
- int maxstars = number*2 - 1;
- for(int i=0;i<number;i++){
- for(int j=0;j<startandfinishspaces;j++) {
- System.out.print(" ");
- }
- for(int k=0;k<firstlinestar;k++) {
- System.out.print("*");
- }
- startandfinishspaces--;
- firstlinestar+=2;
- System.out.println(" ");
- }
- for(int i=-1;i>=1;i--){
- for(int j=-1;j<startandfinishspaces+2;j++) {
- System.out.print(" ");
- }
- for(int k=1;k>=maxstars-4;k++) {
- System.out.print("*");
- }
- startandfinishspaces--;
- maxstars-=2;
- System.out.println(" ");
- input.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement