Write a program in java to input a string/sentence and print those characters which are present at even indexes except 0 index from the string.
THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO A SENTENCE AND PRINT THOSE CHARACTERS WHICH ARE PRESENT AT EVEN INDEXES OF THE STRING EXCEPT 0TH INDEX.
import java.util.*;
class evenPrint
{
public static void main (String args[])
{
Scanner ob = new Scanner (System.in);
System.out.println("Enter a String");
String s = ob.nextLine();
for(int i = 0; i < s.length(); i++)
{
char ch = s.charAt(i);
if(ch!= 0)
{
if(ch%2 == 0)
{
System.out.println("Characters at even indexes = "+ch);
}
}
}
}
}
The above program CODE is compiled and is without any error.
Hope you guys found it helpful.
Please share it with your friends and comment down in the comment section below.
Follow https://askrisfor.blogspot.com/ for more such updates.
Visit us again.
Thank you!!
Comments
Post a Comment