你好,试图弄清楚如何在java中制作以下模式
xoxox
oxoxo
xoxox
我最近在学习,并试图弄清楚几个小时。这是我到目前为止的代码。主要是public static String textBoxString(int rows, int cols, char c1, char c2) 下的最后一部分
public class TextBoxTester {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = TextBox.textBoxString(3);
System.out.println(s);
s = TextBox.textBoxString(4, '+');
System.out.println(s);
s = TextBox.textBoxString(3, 4);
System.out.println(s);
s = TextBox.textBoxString(3, 5, 'x', 'o');
System.out.println(s);
}
}
public class TextBox {
public static String textBoxString(int side) {
String s = "";
for (int i = 0; i < side; i++) {
for (int j = 0; j < side; j++)
s += "*";
s += "\n";
}
return s;
}
public static String textBoxString(int side, char bChar) {
String s = "";
for (int i = 0; i < side; i++) {
for (char j = 39; j < bChar; j++)
s += bChar;
s += "\n";
}
return s;
}
public static String textBoxString(int rows, int cols) {
String s = "";
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++)
s += "*";
s += "\n";
}
return s;
}
public static String textBoxString(int rows, int cols, char c1, char c2) {
char c = c1;
char d = c2;
String s = "";
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++)
s += c;
if (c == c1) {
c2++;
} else {
c1 = c;
}
s += "\n";
}
return s;
}
}