Advertisement
Guest User

Untitled

a guest
May 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p06_RhombusOfStars {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.        /* int n = Integer.parseInt(scanner.nextLine());
  8.         int spaceCount = n-1;
  9.         int starsCount=0 ;
  10.  
  11.         for (int r = 0; r <n  ; r++) {
  12.             for (int s = 0; s <spaceCount ; s++) {
  13.                 System.out.print(" ");
  14.             }
  15.             System.out.print("*");
  16.             for (int stars = 0; stars < r ; stars ++) {
  17.                 System.out.print(" *");
  18.                 }
  19.             spaceCount --;
  20.             System.out.println();
  21.  
  22.         }
  23.          spaceCount=1;
  24.         starsCount = starsCount -1 ;
  25.         for (int r = 0; r < n-1 ; r++) {
  26.             for (int s = 0; s <  spaceCount ; s++) {
  27.                 System.out.print(" ");
  28.             }
  29.             for (int s= 0; s < starsCount ; s ++) {
  30.                 System.out.print(" *");
  31.                 System.out.println("*")
  32.  
  33.             }
  34.             starsCount -=1;
  35.             spaceCount++;
  36.  
  37.         }
  38.  
  39.  
  40.     }
  41. }*/
  42.         int rhombusSideSize = Integer.parseInt(scanner.nextLine());
  43.     String starSign = "* ";
  44.  
  45.         for (int i = 1; i <= rhombusSideSize; i++) {
  46.                 rhombusLineOutput(rhombusSideSize, i, starSign);
  47.                 }
  48.  
  49.                 for (int i = rhombusSideSize - 1; i > 0 ; i--) {
  50.                 rhombusLineOutput(rhombusSideSize, i, starSign);
  51.                 }
  52.                 }
  53.  
  54. static void rhombusLineOutput(int rhombusSideSize, int signsCount, String fillSign){
  55.         int spacesCount = rhombusSideSize - signsCount;
  56.         String outputString = stringRepeater(" ", spacesCount);
  57.         outputString += stringRepeater(fillSign, signsCount);
  58.         System.out.println(outputString);
  59.         }
  60.  
  61. static String stringRepeater (String stringToRepeat, int stringRepeatCount){
  62.         String outputString = "";
  63.         for (int i = 0; i < stringRepeatCount; i++) {
  64.         outputString += stringToRepeat;
  65.         }
  66.         return outputString;
  67.         }
  68.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement