import java.util.*
public class baiduA
{
public static void main(String[] args)
{
System.out.print("please put a line number: ")
Scanner in = new Scanner(System.in)
String l = in.next()
int row = 1
for (int n = 1n <= 5n++, row++)
{
for (int i = 1i <= rowi++)
{
System.out.print(l)
}
System.out.println()
}
}
}
运行结果:
package testimport java.util.Scanner
public class Encrypt {
public static void main(String[] args) {
Scanner in = new Scanner(System.in)
String temp = ""
while ((temp = in.next()) != null) {
System.out.println(temp)
temp = encrypt(temp)
System.out.println(temp)
}
if (null != in) {
in.close()
}
}
public static String encrypt(String in) {
StringBuilder temp = new StringBuilder(in)
if (in.length() > 1) {
char a = temp.charAt(0)
temp.deleteCharAt(0)
temp.append(a)
} else {
return in
}
return temp.toString()
}
}
//供参考,代码应该没问题,难点主要是在如何匹配连续字符串,这点有小技巧public class TestBaiduKnow {
public static void main(String args[]) throws Exception {
String s = "Sdabcdk3abcdabcdgg3abcdabcdabcd55fg"
char[] in = s.toCharArray()
char[] out = "abcd".toCharArray()
int cnt = 0
cnt = maxfleg(in, out)
System.out.println("出现次数: " + cnt)
}
private static int maxfleg(char[] inputstr, char[] outputstr) {
String s = ""
String s2 = ""
for (int i = 0 i < outputstr.length i++)
s2 += outputstr[i]
int cnt = 0
int maxcnt = 0
for (int i = 0 i < inputstr.length - 4 i++) {
for (int j = i j < i + 4 j++)
s += inputstr[j]
if (s.equals(s2)) {
cnt += 1
i += 3
if (cnt > maxcnt)
maxcnt = cnt
} else
cnt = 0
s = ""
}
return maxcnt
}
}