Computer Science, asked by ridjdjdjdjddj, 9 months ago

(Replacing - word)
Consider the following statement
"January 26 is celebrated as the Republic day of India”.
Write a program to change 26 to 15,
January to August, Republic
to Independence and finally print “August 15 is celebrated as the
Independence day of India"
Plz help we write this program in java.

Answers

Answered by Mora22
11

answer

public static void main()throws Exception

{

String s="January 26 is celebrated as the Republic Day of India";

s=s.replace("January", "August");

s=s.replace("26", "15");

s=s.replace("Republic", "Independence");

System.out.println(s);

}

}

Result:

OUTPUT:

August 15 is celebrated as the Independence Day of India

Answered by tejassidhwani
9

Answer:

class ProjectQ1

{

   public static void main()

   {

       String s="January 26 is celebrated as the Republic Day of India";

       s=s+" ";

       String a="",st="";

       int l=s.length();

       for(int i=0;i<l;i++)

       {

           char c=s.charAt(i);

           if(c!=' ')

               a=a+c;

           else

           {

               if(a.equals("26"))

                   st=st+" "+"15";

               else if(a.equals("January"))

                   st=st+" "+"August";

               else if(a.equals("Republic"))

                   st=st+" "+"Independence";

               else

                   st=st+" "+a;

               a="";

           }

       }

       System.out.println("New String is");

       System.out.println(st);

   }

}

Explanation:

Similar questions