When I am passing the argument s in System.out.println(s);
The out put is as follows:-
Java is easy to learn!
Java is object-oriented!
Java is platform-independent!
When I pass the same argument consecutively in others as under:-
System.out.println(s);
System.out.println(s);
System.out.println(s);
The outpurt should be like
Java is easy to learn!
Java is object-oriented!
Java is platform-independent!
Java is easy to learn!
Java is object-oriented!
Java is platform-independent!
Java is easy to learn!
Java is object-oriented!
Java is platform-independent!
Java is easy to learn!
Java is object-oriented!
Java is platform-independent!
But the output is different from my expectation:-
Java is easy to learn!
Java is easy to learn!
Java is easy to learn!
Java is easy to learn!
Java is object-oriented!
Java is object-oriented!
Java is object-oriented!
Java is object-oriented!
Java is platform-independent!
Java is platform-independent!
Java is platform-independent!
Java is platform-independent!
How?
Though I am Getting the proper out put. But did not get the way it is being processed.
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Dirk_Struan
12 July 2021, 15:52
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 is object-oriented!");
print("Java is platform-independent!");
}
public static void print(String s) {
//write your code here
System.out.println(s);
System.out.println(s);
System.out.println(s);
System.out.println(s);
}
}
0
Misiu
14 October 2020, 14:22
All is correct.
System.out.println(s);
System.out.println(s);
System.out.println(s);
System.out.println(s);
Four times the same string.
If s = "Java is easy to learn!" then print() method prints 4 times "Java is easy to learn!".
If s = "Java is object-oriented!" then print() method prints 4 times "Java is object-oriented!".
And so on...
0
Dinesh
14 October 2020, 14:58
Java might be easy as level goes up but its seems a bit difficult for me for now
So
I think that Either I am unable to explain the problem or you didn`t got What I was asking .
Both are correct its ok.
but on execution of the all the 4 Sop(s); Consecutively I am not getting how
Java is easy to learn!
Java is easy to learn!
Java is easy to learn!
Java is easy to learn!
Java is object-oriented!
Java is object-oriented!
Java is object-oriented!
Java is object-oriented!
Java is platform-independent!
Java is platform-independent!
Java is platform-independent!
Java is platform-independent!
Is Being processed as output.
I want to know the pattern of this output How?
Please refer the code
and uncomment the Sop(s) statement one by one and observe the output
than it will be much more clear what I am asking for. Hope now I have explained my problem better way. Thanks
public class Solution {
public static void main(String[] args) {
print("Java is easy to learn!");
print("Java is object-oriented!");
print("Java is platform-independent!");
}
public static void print(String s) {
//write your code here
// System.out.println(s);
// System.out.println(s);
// System.out.println(s);
//System.out.println(s);
}
}
0
Misiu
14 October 2020, 15:23
Instruction: print("Java is easy to learn!"); invokes print() method and delivers string "Java is easy to learn!" to it.
Method print(String s) does its work: 4 times prints s. And because s = "Java is easy to learn!",
print(String s) prints 4 times string "Java is easy to learn!". And this is the end of print() method.
Then code goes to instruction: print("Java is object-oriented!");. This instruction invokes print() method and delivers string "Java is easy to learn!" to it. And so on...
If I uncomment one statement, output will be:
Java is easy to learn!
Java is object-oriented
Java is platform-independent!
If I uncomment two statements, output will be:
Java is easy to learn!
Java is easy to learn!
Java is object-oriented
Java is object-oriented
Java is platform-independent!
Java is platform-independent!
And so on...
0