In my java code the line String st = sc.nextLine();
is not taking input when the code is running and when instead I use sc.next();
the code works properly can you please tell me why sc.nextLine();
is not working
import java.lang.*;
import java.util.*;
/**?Chef wrote some text on a piece of paper and now he wants to know how
many holes are in the text. What is a hole? If you think of the paper as
the plane and a letter as a curve on the plane, then each letter divides
the plane into regions.For example letters "A", "D", "O", "P","R" divide
the plane into two regions so we say these letters each have one hole.
Similarly, letter "B" has 2 holes and letters such as "C", "E", "F","K"
have no holes. We say that the number of holes in the text is equal to
the total number of holes in the letters of the text.
Help Chef to determine how many holes are in the text.
Input
First line contains a single integer T <= 40, the number of test cases.
T test cases follow. The only line of each test case contains a non-empty
text composed only of uppercase letters of English alphabet. The length
of the text is less then 100. There are no any spaces in the input.
Output
For each test case,output a single line containing number of holes in the corresponding txt
Example
Input:
2
CODECHEF
DRINKEATCODE
Output:
2
5
*/
class Holes {
public static void main(String[] args) {
int i, Testcase;
int holes, space = 0, j;
Scanner sc = new Scanner(System.in);
Testcase = sc.nextInt();
for (i = 0; i < Testcase; i++) {
holes = 0;
space = 0;
String st = sc.nextLine();
if (st.length() < 100) {
char[] letter = st.toCharArray();
for (j = 0; j < st.length(); j++) {
if (letter[j] == ' ') {
space++;
}
}
for (j = 0; j < st.length(); j++) {
if (space == 0) {
if (letter[j] == 'A' || letter[j] == 'D'
|| letter[j] == 'O' || letter[j] == 'P'
|| letter[j] == 'R') {
holes = holes + 1;
}
if (letter[j] == 'B') {
holes = holes + 2;
}
}
}
}
if (st == st.toUpperCase() && space == 0) {
System.out.println(holes);
}
}
}
}