This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Napišite metodu koja prima string i vraća broj pojavljivanja slova a u tom stringu | |
def vraca_slova(neki_string) | |
i=0 | |
neki_string.split(//).each do |x| | |
if(x == "a") | |
i=i+1 | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### a) Ispišite sve brojeve od 1 do 1000 koji su djeljivi sa 13 ili 7 | |
(1..1000).each do |x| | |
if x%13==0 and x%7==0 | |
print x | |
puts " ima ostatka" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Ispišite sve brojeve od 1 do 100, svaki u svom redu | |
(1..100).each do |x| | |
puts x | |
end | |
### Ispišite brojeve od 17 do 32 u jednom redu, odvojite ih zarezom | |
puts (17..32).to_a.join(",") | |
### Ispišite random brojeve od 50 do 110 u jednom redu, odvojite ih zarezom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Napišite program koji ce ispisivati string od 10 slova i 5 znamenki | |
### i to svaki put u drukcijem rasporedu | |
puts "DesetSlova12345".split(//).shuffle.join | |
### Napišite program koji ce ispisati brojeve od 1 do 10, svaki u svom redu | |
[1,2,3,4,5,6,7,8,9,10].each do |element| | |
puts element | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Ispišite svoje ime i prezime unatrag | |
puts "Igor Kolar".reverse | |
### Ispišite trece slovo svog imena velikim slovom | |
puts "Igor"[2].capitalize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Brojčano na ekranu ispišite koliko godina ima sekundi. | |
### Koliko imate godina ako ste stari 8286 dana? | |
### Brojčano na ekranu ispišite koliko godina ima sekundi. | |
print "#{365*24*60*60} eto, tolko sekundi\n" | |
print "#{8286/365.round} eto, tolko godina \n" |