[Ruby] Returns characters in a pyramid shape according to the entered numbers

The image looks like this.

スクリーンショット 2020-10-20 14.19.16.png

while str = STDIN.gets
  break if str.chomp == "exit"#Returns the string with the line feed code removed from the end of the string
  n=str.to_i#A method that returns a string as an integer
  puts n
  for x in 0..n-1
    (n-x-1).times{printf(" ")}
    for y in 1..2*x+1
      printf("*")
    end
    puts "\n"
  end
end

October 20, 2020

Recommended Posts

[Ruby] Returns characters in a pyramid shape according to the entered numbers
Calculate the difference between numbers in a Ruby array
How to store the information entered in textarea in a variable in the method
[Ruby] I want to output only the odd-numbered characters in the character string
I thought about the best way to create a ValueObject in Ruby
A memorandum to clean up the code Ruby
[Ruby] Learn how to use odd? Even? And count the even and odd numbers in the array!
How to build the simplest blockchain in Ruby
I want to get the value in Ruby
How to check if the characters entered in the Swift Text Field are email addresses
[Swift] How to display the entered characters in Widget via UserDefaults when using WidgetKit
Count the number of occurrences of a string in Ruby
[Ruby / Rails] Set a unique (unique) value in the class
How to launch another command in a Ruby program
Display a balloon message in BarButtonItem of NavigationBar with a size according to the amount of text.
Determine that the value is a multiple of 〇 in Ruby
How to retrieve the hash value in an array in Ruby
The nth and n + 1st characters of a Ruby string
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
Create a method to return the tax rate in Java
[Ruby] How to retrieve the contents of a double hash
How to add the same Indexes in a nested array
I want to create a Parquet file even in Ruby
Apply CSS to a specific View in Ruby on Rails
I wrote a code to convert numbers to romaji in TDD
[Ruby] How to batch convert strings in an array to numbers
[Swift] When you want to know if the number of characters in a String matches a certain number ...
Ruby Learning # 2 Drawing a Shape
Multiplication in a Ruby array
[Ruby] Find numbers in arrays
[Ruby] How to count even or odd numbers in an array
I tried to illuminate the Christmas tree in a life game
I tried to write code like a type declaration in Ruby
[Ruby] I want to put an array in a variable. I want to convert to an array
A memorial service for the library used when competing in Ruby
Replace with a value according to the match with a Java regular expression
Add a time stamp to the JAR file name in Gradle
Things to remember and concepts in the Ruby on Rails tutorial
I want to change the value of Attribute in Selenium of Ruby
(Ruby on Rails6) Create a function to edit the posted content
How to display characters entered in Spring Boot on a browser and reference links [Introduction to Spring Boot / For beginners]