Computer Science, asked by beherasjsatya, 1 year ago

wap to accept a sentence and display only the word having even number of characters in java

Answers

Answered by Anonymous
2

CODE

import java.util.*;

class even_words

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the sentence");

String s=sc.nextLine();

String w="";

s=s+" ";

int c=0;

for(int i=0;i<s.length();i++)

{

char ch=s. charAt(i);

if(ch!=' ')

{

w=w+ch;

c++;

}

else

{

if(c%2==0)

{

System.out.println(w);

}

}

w="";

}

}

}

Similar questions