Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mariiaKolokolova
Created April 30, 2020 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariiaKolokolova/c034feb8ff6356264f67b449a218989e to your computer and use it in GitHub Desktop.
Save mariiaKolokolova/c034feb8ff6356264f67b449a218989e to your computer and use it in GitHub Desktop.
package maricka.kolokolova;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Input your number");
int n;
n = sc.nextInt();
String s = "*";
String str;
int st;
int r = 0;
st = n * 2 - 1;
for (int i = 1; i <= st; i = i + 1) {
if (i <= n) {
r = r + 1;
str = String.format("%1$-" + r + "s", s).replace(' ', '*');
System.out.println(str);
} else {
r = r - 1;
str = String.format("%1$-" + r + "s", s).replace(' ', '*');
System.out.println(str);
}
}
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment