Write code without using try or exception statementsSolution

**Write code without using try or exception statements**

Solution

Hw6pr6.java


import java.util.Scanner;

public class Hw6pr6 {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.print(\"Enter the sentence: \");
       String s = scan.nextLine();
       String newStr = \"\";
       for(int i=0; i<s.length(); i++){
           char ch = s.charAt(i);
           if((ch >=\'A\' && ch <=\'Z\') || (ch >=\'a\' && ch <=\'z\')){
               newStr = newStr+ch;
           }
       }
   boolean flag = true;
       for(int i=0; i<newStr.length(); i++){
           if(Character.toLowerCase(newStr.charAt(i)) != Character.toLowerCase(newStr.charAt(newStr.length()-1-i))){
               flag = false;
           }
       }
       if(flag){
           System.out.println(\"Given string is a plaindrome\");
       }
       else{
           System.out.println(\"Given string is not a plaindrome\");
       }
   }

}

Output:

Enter the sentence: Eva, Can I Stab Bats In A Cave?
Given string is a plaindrome

**Write code without using try or exception statements**SolutionHw6pr6.java import java.util.Scanner; public class Hw6pr6 { public static void main(String[] arg

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site