HollowDiamond Java

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

package loops;

import java.util.Scanner;
public class HollowDiamond {

public static void main(String[] args) {


Scanner s1 = new Scanner(System.in);
System.out.println("How many lines?");
int lines = s1.nextInt(); // lines = 5
int i_s = 1;
int l_s = lines/2;
for(int i = 1; i<= lines; i++) {

for(int k = 1; k<=l_s; k++) {


System.out.print(" ");
}
if (i <= lines/2 ) {
l_s -= 1;//upper half
}
else {
l_s += 1;//lower half
}

if (i == 1 || i == lines) {
System.out.print("*");
}
else {
System.out.print("*");
// inner spaces
for(int j=1; j<=i_s;j++) {
System.out.print(" ");
}

// incre/decre of inner space


if (i <= lines/2 ) {
i_s += 2;//upper half
}
else {
i_s -= 2;//lower half
}

System.out.print("*");
}

System.out.println(" "); // go to next line


}
}

You might also like