Page 447 - CA_Blue( J )_Class10
P. 447

{
                                     names[i]=sc.nextLine();
                                }
                                System.out.println("Words are:");
                                for (int i = 0; i < l - 1; i++) {
                                    int lastIndex = names[i].length() - 1;
                                     if(names[i].charAt(0)=='a'||names[i].charAt(0)=='A'||names[i].
                                     charAt(lastIndex)=='a'||names[i].charAt(lastIndex)=='A')
                                    {
                                        System.out.println(names[i]);
                                    }
                                }
                            }
                        }
                    14.  Define a class to accept a string, and print the characters with the uppercase and lowercase reversed, but all the other
                       characters should remain the same as before.                                                 [2022]
                        EXAMPLE: INPUT   :  WelCoMe_2022
                        OUTPUT         :   wELcOmE_2022

                   Ans. import java.util.Scanner;
                        public class Rev
                        {
                            public static void main()
                            {
                                Scanner sc = new Scanner(System.in);
                                String st;
                                String nSt = "";
                                System.out.print("Enter a string:");
                                st = sc.nextLine();
                                int l = st.length();
                                for (int i = 0; i < l; i++)
                                {
                                    if (Character.isUpperCase(st.charAt(i)))
                                    {
                                        nSt = nSt + Character.toLowerCase(st.charAt(i));
                                    }
                                    else if (Character.isLowerCase(st.charAt(i)))
                                    {
                                        nSt = nSt + Character.toUpperCase(st.charAt(i));
                                    }
                                    else
                                    {
                                         nSt = nSt + st.charAt(i);
                                    }
                                }
                                System.out.println(nSt);
                            }
                        }
                    15.  Define a class to accept two strings of same length and form a new word in such a way that, the first character of the first word
                       is followed by the first character of the second word and so on.                             [2022]
                        Example:  Input string 1 - BALL
                        Input String 2- WORD
                        OUTPUT: BWAOLRLD
                   Ans. import java.util.Scanner;
                       public class StrConcat
                       {


                                                                                                                       445
                                                                                                       String Handling  445
   442   443   444   445   446   447   448   449   450   451   452