ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the next() function

Ruby Example: Write a program to demonstrate the next() function.
Submitted by Nidhi, on December 16, 2021

Problem Solution:

In this program, we will create 4 integer variables with some initial value. Then we will use the next() function to get the next integer value. The next() function returns the 1 incremented value of the given number.

Program/Source Code:

The source code to demonstrate the next() function is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate 
# the next() function

num1 = 10;
num2 = -10;
num3 = 15;
num4 = -15;

print "Num1: ",num1.next(),"\n";
print "Num2: ",num2.next(),"\n";
print "Num3: ",num3.next(),"\n";
print "Num4: ",num4.next(),"\n";

Output:

Num1: 11
Num2: -9
Num3: 16
Num4: -14

Explanation:

In the above program, we created num1, num2, num3, num4 that are initialized with 10, -10, 15, -15. Then we called the next() function to get the number incremented by 1 and printed the result.

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.