0

simple question: this will look like after the run:

          text:
          2
          4
          2 text

but i want this:

text: 2 - 4

2 text

System.out.println("text:");
            for (int i = 0; i < tomb.length; i++) {
                if (tomb[i] % 2 == 0) {
                    System.out.println("" + tomb[i]);
                    db++;               
                }     
            }        
            System.out.println(db + " text");
1
  • println litteraly means printline, which prints out the text with a new line afterwards. You can use print if you want no new line. Commented May 2, 2016 at 15:22

2 Answers 2

4

use System.out.print() everywhere in your code, not System.out.println(); wich is meant to print on a different line each time

Sign up to request clarification or add additional context in comments.

Comments

2

Change this

System.out.println("" + tomb[i]);

to

System.out.print("" + tomb[i]);

Edit: Actually you also have to change this

System.out.println("text:");

to

System.out.print("text:");

Because the printer sets the cursor on the next new line.

1 Comment

also need to add the dash 2 - 4 ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.