1 / 2
Jan 2022

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String sname;
int i,j=0;
int testcases = sc.nextInt();
for (i = 0; i <testcases; i++) {
sname=sc.next();
int slength = sname.length()/2;
while (j<slength) {
System.out.println(sname.charAt(j));
j=j+2;

  }
    
}

}
}
Can someone help me with the error. I am getting wrong answer

  • created

    Jan '22
  • last reply

    Jan '22
  • 1

    reply

  • 615

    views

  • 2

    users

  • 2

    links

Have you tried running and testing your code? When I give it the sample input given in the problem, it gives

y
o
c

instead of the expected

y
po
i
ntc

Suggest you try it on ideone and figure out what’s wrong.

STRHH6