Implement the print method
In the print method, display the passed string 4 times. Each time, on a new line.
Requirements:
1. The program should display text on the screen.
2. The main method should not call System.out.println or System.out.print.
3. The print method should display the text on the screen.
4. The main method should call the Solution class's print method exactly twice.
5. The print method should display the string 4 times. Each time, on a new line.
code
package com.codegym.task.task02.task0201;
/*
Implement the print method
*/
public class Solution {
public static void main(String[] args) {
print("Java is easy to learn!");
print("Java opens many opportunities!");
}
public static void print(String s) {
//write your code here
}
}
what will be the output and please explain also?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Mamee
4 February 2019, 03:15
Hello!
This is my first time answering and this lesson was quite a bit ago for me, but, I'm gonna give this a shot. You have not learned "for loops" yet, so, without trying to use terms or methods that may confuse matters...
The output should be that both lines, Java is easy to learn! and Java opens many opportunities!, should both print out four times each, which should print eight lines of text.
On line 13, print(String s), in essence, says that the print("Java is easy to learn!"); on line 9 and the print("Java opens many opportunities!"); on line 10 are the same as "s". So, if you type System.out.println(s); on line 14, it will print one each of line 9 and 10, so... if you also type System.out.println(s); three more times, it will now print each line four times, which will satisfy the assignment. I really hope that made sense. :)
+3
Kaushal
3 February 2019, 21:09
There are 2 ways of doing this....
1. Use For or While loop:
2. Literally print the line 4 times:
Hope this helps XD +2
Devi Prasanna Lakshmi Jettiboyana
3 February 2019, 13:28
Java is easy to learn!
Java is easy to learn!
Java is easy to learn!
Java is easy to learn!
Java opens many opportunities!
Java opens many opportunities!
Java opens many opportunities!
Java opens many opportunities!
You have to use for loop in print method.
0