Java program to accept a sentence and display the words having double sequences. (eq- I Like Rabbit---- rabbit)
import java.util.Scanner;
public class demo{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the String: ");
String str = sc.nextLine();
sc.close();
String strArray[] = str.split(" ");
for(String temp : strArray) {
for(int i=0;i<temp.length()-1;i++) {
if(temp.charAt(i) == temp.charAt(i+1)){
System.out.println(temp);
break;
}
}
}
}
}
Comments
Post a Comment