1
How to print two variables on the same line (without skipping)? I’ve tried print instead of puts but it didn’t work.
1
How to print two variables on the same line (without skipping)? I’ve tried print instead of puts but it didn’t work.
2
Use the concatenation character +
print variavel1 + " " + variavel2
you can use this way to interpret variables within a string as well:
print "Primeira variavel: #{variavel1} Segunda variavel: #{variavel2}"
you can pass as if they were 2 parameters
print variavel1,variavel2
Just a complement, give preference to the second way, instead of the first is much more performative and is a good practice.
1
It worked for me:
x = 1
y = 2
print x, y
print x
print y
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
It works if the variable is initialized with defined values, but if I put a gets happens this problem I quoted
well, first check if you have a line break in your string. See if this solves your problem: print variable1.delete(' n'),variable2
0
I used a gets.chomp and it worked.
Browser other questions tagged ruby
You are not signed in. Login or sign up in order to post.
Can you give an example of what you did? for me the
print
works http://ideone.com/PgRQpq– Maniero
I will repeat, you must [Edit] the question and put the code you are using.
– Maniero