Professional Documents
Culture Documents
Character at Odd Position
Character at Odd Position
Write a Java program to print the characters at the odd position of a given string
## Input
Hey there!
## Output
e hr!
## Explanation
> All the characters (including whitespace) at the odd position of the string `Hey
there!` are printed.
## Solution:-
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String input = s.nextLine();
s.close();
char[] result = input.toCharArray();
for(int i=1;i<result.length;i=i+2){
System.out.print(result[i]);
}
}
}