def main(args: Array[String]) {
val in = new Scanner(System.in)
var T: String = null
var P: String = null
var cand: String = null
var pos: Int = 0
var i: Int = 0
System.out.print("Enter a text string T: ")
T = in.nextLine()
System.out.print("Enter a pattern string P: ")
P = in.next()
println()
pos = 0
while (pos <= T.length - P.length) {
cand = T.substring(pos, pos + P.length)
if (P == cand) {
println(T)
i = 0
while (i < pos) {
System.out.print(" ")i += 1 // Error : Value i is not a member of Unit
}
println(P)
println()
}
pos += 1
}
in.close()
}
}
答案 0 :(得分:5)
您应该在System.out.print(" ")
之后中断或使用System.out.print(" "); i += 1
。否则,您只需在i
System.out.print(" ")
上呼叫成员Unit
。