Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class p06_RhombusOfStars {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- /* int n = Integer.parseInt(scanner.nextLine());
- int spaceCount = n-1;
- int starsCount=0 ;
- for (int r = 0; r <n ; r++) {
- for (int s = 0; s <spaceCount ; s++) {
- System.out.print(" ");
- }
- System.out.print("*");
- for (int stars = 0; stars < r ; stars ++) {
- System.out.print(" *");
- }
- spaceCount --;
- System.out.println();
- }
- spaceCount=1;
- starsCount = starsCount -1 ;
- for (int r = 0; r < n-1 ; r++) {
- for (int s = 0; s < spaceCount ; s++) {
- System.out.print(" ");
- }
- for (int s= 0; s < starsCount ; s ++) {
- System.out.print(" *");
- System.out.println("*")
- }
- starsCount -=1;
- spaceCount++;
- }
- }
- }*/
- int rhombusSideSize = Integer.parseInt(scanner.nextLine());
- String starSign = "* ";
- for (int i = 1; i <= rhombusSideSize; i++) {
- rhombusLineOutput(rhombusSideSize, i, starSign);
- }
- for (int i = rhombusSideSize - 1; i > 0 ; i--) {
- rhombusLineOutput(rhombusSideSize, i, starSign);
- }
- }
- static void rhombusLineOutput(int rhombusSideSize, int signsCount, String fillSign){
- int spacesCount = rhombusSideSize - signsCount;
- String outputString = stringRepeater(" ", spacesCount);
- outputString += stringRepeater(fillSign, signsCount);
- System.out.println(outputString);
- }
- static String stringRepeater (String stringToRepeat, int stringRepeatCount){
- String outputString = "";
- for (int i = 0; i < stringRepeatCount; i++) {
- outputString += stringToRepeat;
- }
- return outputString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement