-
-
Save mariiaKolokolova/c034feb8ff6356264f67b449a218989e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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