concat方法是一个拼接方法。
看API中写的是这样的:
这个例子就是非常形象。
关于concat(String str) 与 +号的不同的参考博客:
http://www.iteye.com/problems/41712
CODE.indexOf(String s)方法是检索s是否在CODE中出现,出现的位置是第几个。或者是s字符串出现的首地址位置是多少,返回的是一个整型。
这里我们使用将目标字符串s再次拼接一次,然后用indexOf()检测就可以了。实现起来很简单,而且效果非常好。
代码如下:
public static void
Loopback
(){
String s = StdIn.
readLine
()
;
String t = StdIn.
readLine
()
;
if
(s.length() == t.length())
if
(s.concat(s).indexOf(t) >=
0
){
//indexof()是一个查找是否存在有字符串的方法
StdOut.
println
(s.concat(s))
;
StdOut.
println
(s.concat(s).indexOf(t))
;
StdOut.
println
( s +
" is the circulor rotation of "
+ t)
;
}
else
{
StdOut.
println
( s +
" is not the circulor rotation of "
+ t)
;
}
}