2

私は得た

String table[][]= new String [i][j];
Scanner insertN = new Scanner(System.in);
int N= insertN.nextInt ();

table[i][j]="-----";
int number1=1;
int number2=2;

最初からn文字( "-")に移動し、それをnumber(1)に置き換えるにはどうすればよいですか。

最初のNが2の場合-プログラムは表11に書き込みます---。
2番目のNが2の場合-プログラムは表1122-に書き込みます

4

1 に答える 1

0
String table[][] = new String[i][j];
table[i][j] "-----";
Scanner insertN = new Scanner(System.in);
int number1 = 1;
int number2 = 2;

int N = insertN.nextInt();
int total = N;

//build a temporary string containing as many '1's as indicated by n
String tmp = "";
for (int k = 0; k < N; k++) tmp = tmp + number1;

N = insertN.nextInt();
total = total + N;
for (int k = 0; k < N; k++) tmp = tmp + number2;

//replace the original string with the '1's and the substring of table[i][j]
//starting at position n and continuing to the end
table[i][j] = tmp + table[i][j].substring(total, table[i][j].length());
于 2012-12-10T21:26:55.433 に答える