Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to stop new Line in java?

My code output is like this:

"Please enter your name: "

_ <-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How do I make my code like this:

"Please enter your name: _ <-"

this my code

import java.util.Scanner;

public class input {
    public static void main(String[] args) {
        System.out.println("Please enter your name: ");
        Scanner Input = new Scanner(System.in);
        String inp = Input.nextLine();
        
    }
}

>Solution :

Check your line System.out.println("Please enter your name: ").

Here, println adds a new line \n after the print statement.

To avoid adding a new line, replace println with print.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading