为什么会输出整个字符串“1fish2fish”…
import java.util.Scanner;
class Main {
public static void main(String[] args) {
String input = "1,fish,2,fish";
Scanner sc = new Scanner(input);
sc.useDelimiter(",");
System.out.print(sc.nextInt());
System.out.println(sc.next());
System.out.print(sc.nextInt());
System.out.println(sc.next());
}
}
但即使我输入“1,fish,2,fish”,它只会打印出“1fish2”?
import java.util.Scanner;
class Main {
public static void main(String[] args) {
System.out.println("Enter your string: ");
Scanner sc = new Scanner(System.in);
sc.useDelimiter(",");
System.out.print(sc.nextInt());
System.out.println(sc.next());
System.out.print(sc.nextInt());
System.out.println(sc.next());
}
}