Computer Science, asked by alokverma651, 6 days ago

System.out.println ("Average = " + avg + "\n" + "Percentage = " + per);

In this statement why \n is puted in double inverted commas. ​

Answers

Answered by ajb7899
1

Answer:

\n is an escape sequence which will be printing the text in the new line.

Output will be:-

Average = 75

Percentage = 90

(The values are chosen randomly)

Answered by BrainlyProgrammer
6

Answer:

\n is an escape sequence which is used for moving to next line.

Escape sequence are some characters which are used to control the cursor in order to get formatted output.

In your given statement,

 \green{ \sf{System.out.println ("Average = " + avg + "\backslash \: n" + "Percentage = " + per);}}

Let's assume average is 90.2 and percentage is 90.2

Then your output will be in the following format,

Average = 90.2

Percentage = 90.2

Other commonly used escape sequence:-

  • \" - To print double qoute
  • \\ - To print backslash
  • \' - To give Single quote
  • \n - New line / To go to next line
  • \t - Horizontal tab

Moreover, do not forget to put escape sequence in double quotes otherwise you won't get formatted output.

Similar questions