x
我必须编写一个程序,该程序接受两个输入的字符并使用一种方法将它们打印出来。到目前为止,它将输出数字而不是字符。我该如何解决?
int length;
char ch1;
char ch2;
System.out.print("Enter a character: ");
ch1 = input.nextLine().charAt(0); //input refers to scanner.
System.out.print("Enter second character: ");
ch2 = input.nextLine().charAt(0); //input refers to scanner.
System.out.print("Enter the length of the line: ");
length = input.nextInt(); //input refers to how many times the characters ar$
draw_line(length, ch1, ch2);
//Method starts here.
public static void draw_line(int length, char ch1, char ch2){
for (int i = 0; i < length; ++i){
System.out.print(ch1 + ch2);
}
}