in this task i have to write word on a single line with a space .

/* Text display
Write a function that displays the passed string (word) three times in the same line.
    Words must be separated by a space and don’t have to merge into one.
*/
public class Solution
{
    public static void print3(String s)
    {

System.out.print(s+" ");
System.out.print(s+" ");
System.out.print(s);

    }
    public static void main(String[] args)
    {
        print3("window");
        print3(" file");
    }
}

it is giving out like " windows windows windows file file file " and the error is " it has not a pass testing . "

asked 12 Mar '15, 18:29

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
4311324
accept rate: 0%

edited 13 Mar '15, 07:15

Elleonora%20Carry's gravatar image

Elleonora Carry ♦♦
275


12next »

//try this buddy, it will definitely do the job

!! hidden by admin as breaking the Honor Code - http://community.javarush.net/articles/67-honorcode

link
This answer is marked "community wiki".

answered 12 Mar '15, 22:55

AristocratSudip's gravatar image

AristocratSudip
163
accept rate: 4%

edited 13 Mar '15, 06:20

Elleonora%20Carry's gravatar image

Elleonora Carry ♦♦
275

According to Honor Code - http://community.javarush.net/articles/67-honorcode - it's prohibited to post the solution that pass the tests. Please give a clue to other people, not to post your solution!

Hide your comment

(13 Mar '15, 06:18) Elleonora Carry ♦♦

i wrote this code beacuse it is not working . have some problems in it . to point out the problem and hint me the right one

(13 Mar '15, 11:18) Muhammad Has...

My previous comment was for AristocratSudip

About your code: If in main method you write

print3("first");
print3("second");

then the output will be the only one line

first first firstsecond second second

See, firstsecond do not separated

But you need two lines:

first first first
second second second
(13 Mar '15, 13:28) Elleonora Carry ♦♦

main function is also written as you are saying . here i have to write function print3() to get answear . i am facing problem in that function . thanks .

(13 Mar '15, 15:51) Muhammad Has...

next call of your function prints text at the same line, but compiler expects output on the new line

(13 Mar '15, 18:02) Elleonora Carry ♦♦

Hey man-

Just like you understand that the last System.out.print() method shouldn't have a " " concatenated. Maybe you remember there is a method already built into that adds a /n , you know- a new line. Scroll back to your conversation with Risha in lesson 4 and compare your print method with what he gave you.

link

answered 13 Mar '15, 13:07

Once%20the%20King%20of%20Andorra's gravatar image

Once the Kin...
676
accept rate: 11%

" file" without space #maybe

link

answered 13 Mar '15, 16:14

Joseph's gravatar image

Joseph
213
accept rate: 0%

public static void print3(String s) { if(s=="window") {System.out.print(s+" "); System.out.print(s+" "); System.out.print(s);} else { System.out.print(s); System.out.print(s); System.out.print(s); }

}
link

answered 25 Mar '15, 07:42

Khawer%20Sandhu's gravatar image

Khawer Sandhu
1
accept rate: 0%

hey hii.. your program is all perfect. i am going to give u a hint. think on it once. check line no.12 and think how to change the line so that it prints output in a newline..

link

answered 08 Apr '15, 12:45

karuna's gravatar image

karuna
19110
accept rate: 0%

//try this it works fine for me notice that only println in the last statement. got it? public static void print3(String s) { System.out.print(s+" "); System.out.print(s+" "); System.out.println(s);

}
link

answered 16 Apr '15, 11:30

mendark's gravatar image

mendark
1
accept rate: 0%

edited 16 Apr '15, 11:32

public class Solution { public static void main(String[] args) { print3(" I Love programing."); } public class void print3(String s) { System.out.println(s+s+s); } }

link

answered 19 Sep '15, 15:01

Muhammad%20Abubakar's gravatar image

Muhammad Abu...
1
accept rate: 0%

Check if you don't have white space after line with words.

link

answered 06 Apr '17, 06:37

noelo's gravatar image

noelo
102
accept rate: 0%

@Once the Kin...

Thanks for tip Dude

link

answered 25 Jul '17, 14:22

konekszyn's gravatar image

konekszyn
1
accept rate: 0%

  1. System.out.print (s+" ");
  2. System.out.print (s+" ");
  3. System.out.println (s);
link

answered 01 Nov '17, 12:59

Winnermann's gravatar image

Winnermann
111
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×52
×16
×2

Asked: 12 Mar '15, 18:29

Seen: 3,677 times

Last updated: 14 Aug, 01:18