How to print and count number of duplicate Word in the given String.
======================================================================
Codaing Part:
How to print and count number of duplicate Word in the given String
===============================
//Write a java program to find the Duplicate word and occurens time
import java.util.*;
class FindDuplicateWOrd {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
s=s.toLowerCase();
String s1[]=s.split(" ");
//applay the logic
for(int i=0;i<s1.length;i++){
int count=1;
for(int j=i+1;j<s1.length;j++){
if(s1[i].equals(s1[j])){
count++; s1[j]="o";
}
}
if(count>1&& s1[i]!="o")
System.out.println(s1[i]);
}
}
}
Output:
Comments
Post a Comment