PROBLEM:
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 stringHey there!
are printed.
CODE:
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]); |
} |
} |
|
|
|
Comments
Post a Comment