IndexOf for chain space
source link: https://www.codesd.com/item/indexof-for-chain-space.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
IndexOf for chain space
There is a space in the string, but when I run program, it returns -1, that means there aren't spaces in the string Here's the code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.next();
System.out.println(s.indexOf(' '));
}
}
Scanner.next()
returns the next token in the input, and by default, tokens are whitespace separated. i.e. s
is guaranteed not to contain spaces.
Maybe you meant String s = scan.nextLine();
?
Related Articles
SystemTap support for user space application
WPF: OnKeyDown () Is Not Called for the Space Key in the WPF TextBox Derived Control
Disable selectivity for a space
Swift: Disable the bar button for white space / new line text in UITextView with placeholder text
What size is too big for static space allocation
nested java for loop spaces and numbers
Regular expression for @ after space in the text box
indexOf for several options
How to fix UTF encoding for white space?
Regular ruby expression for chains with multiple patterns
Chain space allowed, but not in first or last position
Search only for white spaces in a string in Flex
Php Validation: No Chain Space
Allocation of memory for chain and chart
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK