ESCAPE SEQUENCE IN JAVA

EXAMPLE - 1

/*created by hra
in bluej platform
class 9
roll no. 7*/
class escape_ex
{
    public static void main(String[]args)
    {
        System.out.println("different ways of using backslash n :");
        System.out.println("1. the use of backslash n along with the message");
        System.out.println("Name: Sanjay Kumar \n\n" + "Age: 16 yrs \n" + "Class: X");
        int a = 14, b=26; // here a is used to store value 14 and b is storing 26
        System.out.println("2.The use of backslash n seperated by '+' ");
        System.out.println("First number ="+a+"\n"+"Second number ="+b+"\n"+"Sum="+(a+b));
    }
}

OUTPUT-

different ways of using backslash n :
1. the use of backslash n along with the message
Name: Sanjay Kumar

Age: 16 yrs
Class: X
2.The use of backslash n seperated by '+'
First number =14
Second number =26
Sum=40


EXAMPLE - 2

class escape_ex1
{
    public static void main(String[]args)
    {
        System.out.println("Different ways of using backslash t :");
        System.out.println("1. The use of backslash t along with the message");
        System.out.println("Name :Sanjay Mittal \t\t"+"Age:\t\t"+"16\t"+"years");
        System.out.println("2. The use of backslash t seperated by '+' and within double quotes");
        System.out.println("Name : Sammy Sarkar"+"\t\t"+"Age:"+"\t\t"+"16\t"+"years");
    }
}

OUTPUT

Different ways of using backslash t :
1. The use of backslash t along with the message
Name :Sanjay Mittal Age: 16 years
2. The use of backslash t seperated by '+' and within double quotes
Name : Sammy Sarkar Age: 16 years


Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...