0% found this document useful (0 votes)
14 views1 page

Find Duplicate Words in String

The document presents a Java program that identifies and prints duplicate words from a user-input string. It utilizes a Scanner to read the input, processes the string to find words, and checks for repetitions. The program outputs each duplicate word found in the input string.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Find Duplicate Words in String

The document presents a Java program that identifies and prints duplicate words from a user-input string. It utilizes a Scanner to read the input, processes the string to find words, and checks for repetitions. The program outputs each duplicate word found in the input string.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Program to print Duplicate words in the String

import [Link].*; //Importing packages

import [Link].*;

import [Link].*;

public class Duplicate //declaring class

{ //opening braces of class

public static void main(String[] args) //declaring main method

{ //opening braces of main method

Scanner pa = new Scanner([Link]); //declaring Scanner class

[Link]("Enter a string: ");

String s = [Link]().toLowerCase()+" "; //Store the String and convert it into LowerCase

int e; //To store index of space

for(int i=0;i<[Link]();i+=e) //loop till length of string

e = [Link](' ',i); //storing index of Space

String w = [Link](i,e); //storing word between i and e

int d = [Link](w, e + 1); //to check if word is repeated

if (d>0) //if the word is more than one time in the string

[Link](w); //To print the word

} //closing braces of main method

} //closing braces of class

VARIABLE DATA TYPE FUNCTION


s String To store the String
e Character To store the index of space
i Integer To store the index of the first character
of the word
w Integer To Store the word
d Integer To Count the frequency of Each word

You might also like