How to add a new line?

0171

To add a new line in a string, you can use newline characters specific to the programming language you are working with. Here are examples for several languages:

Java

Use \n for a new line:

String text = "Hello, World!\nThis is a new line.";
System.out.println(text);

Python

Use \n as well:

text = "Hello, World!\nThis is a new line."
print(text)

JavaScript

You can use \n in strings:

let text = "Hello, World!\nThis is a new line.";
console.log(text);

C

In C, use \n in printf:

#include <stdio.h>

int main() {
    printf("Hello, World!\nThis is a new line.\n");
    return 0;
}

HTML

In HTML, use the <br> tag for a line break:

<p>Hello, World!<br>This is a new line.</p>

If you have a specific language in mind or need further assistance, feel free to ask!

0 Comments

no data
Be the first to share your comment!