Groovy Quiz 12 | Strings | Part 1


Reference video | Groovy Playground


1 Point for every correct answer | Let’s Get Started

1.

Guess the output

def name = "Raghav"
println name
println "My name is "+name
 
 
 

2.

Guess the output

def name = "Raghav"
println "My name is "+name
println "My name is ".concat(name)
 
 
 

3.

Guess the output

def name = "Raghav"
println "My name is ${name}"
 
 
 

4.

Guess the output

def name = "Raghav"
println 'My name is ${name}'
 
 
 

5.

Guess the output

def str = """This is a groovy class
and we are learning Strings"""
print str

hint : Using triple single quotes or triple double quotes the String will be printed as it is (including next line)

 

 
 

6.

Guess the output

def str = "Groovy"
print str.length()
 
 
 

7.

Guess the output

def str = "RAGHAV"
print str[2]

hint : index position starts from 0

 
 
 

8.

Guess the output

def str = "RAGHAV"
print str[-3]

hint: negative index position starts from backward and counts from 1 (not zero)

 
 
 

9.

Guess the output

def str = "RAGHAV"
print str.indexOf('V')
 
 
 

10.

Guess the output

def str = "RAGHAV"
print str[0..2]

hint: you can watch the groovy loops video – https://youtu.be/WsRJC9he7t0

 
 
 
 

11.

Guess the output

def str = "RAGHAV"
print str[5..3]

hint: start index position from backward

 
 
 

12.

Guess the output

def str = "RAGHAV"
print str[0,2,4]
 
 
 

12