

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
-
58
README.md eth2.0 Beacon Chain Implements a proof of concept beacon chain for a sharded pos ethereum 2.0. Spec in progress can be found
-
68
The Qualcomm chain-of-trust is a complex, yet straightforward to understand set of processes. Many of you have likely heard the term “...
-
33
#方法一:使用string.Contains方法 string.Contains是大小写敏感的,如果要用该方法来判断一个string是否包含某个关键字keyword,需要把这个string和这个key
-
48
作者八路(企业代号名),目前负责贝壳找房商业化方向的前端工作。 提到常见的字符串匹配算法,一般来说我们会想到一个是朴素算法(...
-
26
简介 最近做项目的时候,发现无论是前端还是后端,indexOf出现的概率都非常频繁,今天我们来看下他的实现原理吧! indexOf的含义 : 给定一个字符串去匹配另一个字符串的下标,如...
-
15
A quiz about type-coercion, indexOf return values, and the principle of lol whoops a bug.A quiz about type-coercion, indexOf return values, and the principle of lol whoops a bug. 03 Mar 2014 Given the following vers...
-
4
go indexOf indexOf indexOf(s, p string) 函数会返回p在s中首次出现的位置,倘如没有则返回-1,本次使用之前提到过的kmp算法来作为indexOf的核心,并用来解决leetcode28题 ...
-
6
Golang strings.Index = JavaScript String indexOf() Theory and Practice ≡
-
6
indexOf 的 >=0 与 !==-1 问题 在一个项目中,别的同事用到了 indexOf,我一般判断都是写成 >=0,而他写作 !==-1...
-
4
April 6, 2023 /
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK