Saturday, 7 May 2022

Switch case in Java

 Problem statement: Return the capital of a state based on input state


        public String getCapital(String state){

            switch(state)

            {

                case "Tamilnadu":

                            return "Chennai";

                 case "Karnataka":

                            return "Bangalore";

                case "Maharastra":

                            return "Mumbai";

                case "Kerala":

                            return "Trivandrum";

                }

                return null;

          }


Input: Tamilnadu

Output: Chennai


No comments:

Post a Comment

Switch case in Java

 Problem statement: Return the capital of a state based on input state          public String getCapital(String state){               switch...