#Ruby can handle both integars and floating points
twenty=20
one_point_two=1.2
#we can add this putting a # before a variable prints
puts "twenty + one_point_two = #{twenty+one_point_two}"
puts 4+4.0
#puts 4+"Ajay" # <=== Try this you will get an error
=begin
you can use an underscore as a thousands divider when writing long numbers; Ruby ignores the underscore.
This makes it easy to read large numbers:
=end
billion=1_000_000_000
puts billion
#creating an Array
first_array = [] #empty array
second_array = Array.new #empty array
third_array =[1,2,3]
puts third_array
first_array.push("Ajay")
second_array[0]="Different ways of adding an object to array"
puts first_array
puts second_array
fourth_array = Array.new(20) #created an array of size 20
puts fourth_array.size
puts fourth_array.length
names = Array.new(4, "Ajay") #names has 4 objects
puts "#{names}"
puts names.length
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.Tuesday, March 31, 2015
Hands on Ruby Numbers and Arrays
Labels:
ruby
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment