import java.util.Scanner; // headers MUST be above the first class
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
Scanner scan = new Scanner("abcdef/ghijkl/out/");
scan.useDelimiter("/");
while(scan.hasNext())
{
System.out.println(scan.next());
}
}
}
这个工程。
您的问题可能是您打开了键盘(System.in)的扫描仪,但没有将键盘输入的值存储在任何地方。你可能会想你的输入设置为变量,就像我已经教会了Java类一直在做:
Scanner scan = new Scanner (System.in);
String input = scan.nextLine(); // input: "abcdef/ghijkl/out/"
String[] stringArray = input.split("/");
for(String i : stringArray)
{
System.out.println(i);
}
你确定有多少串(每串由“/”分隔),你必须阅读? – cse