284,917 views
3 votes
3 votes
If a= ‘ Stay home, Stay safe’ , print its value

a. 3 times in the same line
( 2 x 1 = 2)
b. 2 times in different lines using one print statement

User Gallaxhar
by
2.9k points

1 Answer

17 votes
17 votes

Answer:

Since the language isn’t stated, I’ll give answers in the two most-used (?) languages: Java and Python.

a) To print a’s value 3 times in the same line, in Java we would do:

System.out.print(a+a+a);

In Python, we would write:

print(a*3)

b) 2 times in different lines using one print statement

In Java, we would write

System.out.println(a+”\\”+a+”\\”+a);

In Python we would write:

print(a,a,a,sep=’/n’)

Hope this helps!

User Oleksandr Fentsyk
by
3.0k points