So I want to get the length of the input in java, but the (String.length()) doesn't produce a satisfying result.
So when I type this code:
String c = "hi hello";
System.out.print(c.length());
I get 8 which is correct
but when I type this code:
Scanner s = new Scanner(System.in);
String c = s.next();
System.out.print(c.length());
For "hi hello" is the input, I get 2 not 8. I tried again with different inputs and I found that string.length() have a problem with spaces in inputs. for example, if the input was "123456 78" the output would be 6 not 9. Can you tell me how to get the full length of the input? Thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…