From 15eff421d18c972b7b703f94ff2e6fd980d50339 Mon Sep 17 00:00:00 2001 From: Scarlet-Coder <72255255+Scarlet-Coder@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:03:06 +0530 Subject: [PATCH 1/3] Create sentence_Palindrome.java --- sentence_Palindrome.java | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sentence_Palindrome.java diff --git a/sentence_Palindrome.java b/sentence_Palindrome.java new file mode 100644 index 000000000..26ba1eefa --- /dev/null +++ b/sentence_Palindrome.java @@ -0,0 +1,61 @@ +/* + Print the palindrome words present in the sentence and its frequency. +*/ + + +import java.util.*; +class sentence_Palindrome +{ + String str; + void accept() + { + Scanner sc=new Scanner(System.in); + System.out.println("Enter a sentence"); + str=sc.nextLine(); + str=str.toUpperCase(); + } + + boolean isPalin(String s) + {//checks if the word is Palindrome or not + int l=s.length(); + String rev=""; + for(int i=l-1; i>=0; i--) + { + rev=rev+s.charAt(i); + } + if(rev.equals(s)) + return true; + else + return false; + } + + void main() + { + accept(); + char ch=str.charAt(str.length()-1); + if(ch=='.' || ch=='!' || ch=='?') + { + int freq=0; + StringTokenizer st=new StringTokenizer(str," .!?"); + int c=st.countTokens(); + for(int i=1; i<=c; i++) + { + String w=st.nextToken(); + boolean r=isPalin(w); + if (r==true) + { + System.out.print(w+" "); + freq++; + } + } + System.out.println(); + if(freq!=0) + System.out.println("NUMBER OF PALINDROMIC WORDS =”+ freq); + else + System.out.println("NO PALINDROMIC WORDS"); + } + } + else + System.out.println("INVALID INPUT"); + } +} From 2e91545d4eb23a18ae1ee3c5d9f4c6fc0d177fe2 Mon Sep 17 00:00:00 2001 From: Scarlet-Coder <72255255+Scarlet-Coder@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:04:46 +0530 Subject: [PATCH 2/3] Delete sentence_Palindrome.java --- sentence_Palindrome.java | 61 ---------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 sentence_Palindrome.java diff --git a/sentence_Palindrome.java b/sentence_Palindrome.java deleted file mode 100644 index 26ba1eefa..000000000 --- a/sentence_Palindrome.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - Print the palindrome words present in the sentence and its frequency. -*/ - - -import java.util.*; -class sentence_Palindrome -{ - String str; - void accept() - { - Scanner sc=new Scanner(System.in); - System.out.println("Enter a sentence"); - str=sc.nextLine(); - str=str.toUpperCase(); - } - - boolean isPalin(String s) - {//checks if the word is Palindrome or not - int l=s.length(); - String rev=""; - for(int i=l-1; i>=0; i--) - { - rev=rev+s.charAt(i); - } - if(rev.equals(s)) - return true; - else - return false; - } - - void main() - { - accept(); - char ch=str.charAt(str.length()-1); - if(ch=='.' || ch=='!' || ch=='?') - { - int freq=0; - StringTokenizer st=new StringTokenizer(str," .!?"); - int c=st.countTokens(); - for(int i=1; i<=c; i++) - { - String w=st.nextToken(); - boolean r=isPalin(w); - if (r==true) - { - System.out.print(w+" "); - freq++; - } - } - System.out.println(); - if(freq!=0) - System.out.println("NUMBER OF PALINDROMIC WORDS =”+ freq); - else - System.out.println("NO PALINDROMIC WORDS"); - } - } - else - System.out.println("INVALID INPUT"); - } -} From d206f7e3eed308cdcd4fd543ea4e9be5ede4a4f5 Mon Sep 17 00:00:00 2001 From: Scarlet-Coder <72255255+Scarlet-Coder@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:06:29 +0530 Subject: [PATCH 3/3] Added a program sentence_Palindrome.java The program prints the palindrome words present in the sentence and its frequency. --- sentence_Palindrome.java | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 sentence_Palindrome.java diff --git a/sentence_Palindrome.java b/sentence_Palindrome.java new file mode 100644 index 000000000..f73107523 --- /dev/null +++ b/sentence_Palindrome.java @@ -0,0 +1,62 @@ +/* + Print the palindrome words present in the sentence and its frequency. +*/ + + +import java.util.*; +class sentence_Palindrome +{ + String str; + void accept() + { + Scanner sc=new Scanner(System.in); + System.out.println("Enter a sentence"); + str=sc.nextLine(); + str=str.toUpperCase(); + } + + boolean isPalin(String s) + {//checks if the word is Palindrome or not + int l=s.length(); + String rev=""; + for(int i=l-1; i>=0; i--) + { + rev=rev+s.charAt(i); + } + if(rev.equals(s)) + return true; + else + return false; + } + + void main() + { + accept(); + char ch=str.charAt(str.length()-1); + if(ch=='.' || ch=='!' || ch=='?') + { + int freq=0; + StringTokenizer st=new StringTokenizer(str," .!?"); + int c=st.countTokens(); + for(int i=1; i<=c; i++) + { + String w=st.nextToken(); + boolean r=isPalin(w); + if (r==true) + { + System.out.print(w+" "); + freq++; + } + } + System.out.println(); + if(freq!=0) + System.out.println("NUMBER OF PALINDROMIC WORDS =”+ freq); + else + System.out.println("NO PALINDROMIC WORDS"); + } + } + else + System.out.println("INVALID INPUT"); + } +} +© 2020 GitHub, Inc.