如何在java中以列显示乘法表。不使用额外的java函数,只使用循环和条件
我想在三列三行中显示这些值。这是我的代码:如何在java中以列显示乘法表。不使用额外的java函数,只使用循环和条件,java,loops,conditional,Java,Loops,Conditional,我想在三列三行中显示这些值。这是我的代码: public class MultiplicationTable { public static void main(String[] args) { for(int i=2;i<=10;i++){ System.out.println(); System.out.println(" The table " + i); for(int j=2;j<
public class MultiplicationTable {
public static void main(String[] args) {
for(int i=2;i<=10;i++){
System.out.println();
System.out.println(" The table " + i);
for(int j=2;j<=10;j++) {
System.out.println(" " +i + " x " + j + " = " + i*j + "\t");
}
}
}
}
公共类乘法表{
公共静态void main(字符串[]args){
对于(inti=2;i(更正)愚蠢的我来说;只是普通的表,但有3列
您可以写“\u00d7”或“×”,而不是“x”,这是真正的数学运算符×
public static void main(String[] args) {
final String TAB = " ";
for(int y = 0; y < 3; y++) {
for(int j = 2; j <= 10; j++) {
for (int x = 0; x < 3; x++) {
int i = 2 + y*3 + x;
System.out.printf("The table %2d " + TAB, i);
System.out.printf("%2d x %2d = %3d" + TAB, i, j, i*j);
}
System.out.println();
}
System.out.println();
}
}
publicstaticvoidmain(字符串[]args){
最终字符串选项卡=”;
对于(int y=0;y<3;y++){
for(int j=2;jfor(int i=2;iString temp=”“;
字符串lbl=“TABLE#”;
int num=10,
行长=10,
收集长度=3;
int tableNumber=1,
计数器=收集长度,
指数=1;
对于(int colLabel=index;colLabel),请不要包含“非常感谢”在你的问题中。这是无用的噪音。还有,你尝试过什么?问题是什么?如果你不告诉我们你想做什么以及为什么它不起作用,我们到底能帮什么忙?你想要的输出是什么?乘法表的通常格式是一个nxn表,表示1和n(包括)之间所有整数对的乘积.这就是您想要的吗?我的代码仅显示值在一列中,我希望它在三列和三行中被更正;有两次y++而不是第二次x++。复制错误。我希望这样:!
for(int i=2;i<=10;i++){
System.out.println();
System.out.println(" The table " + i);
for(int j=2;j<=10;j++) {
System.out.println( i + " x " + j + " = " + i*j );
}
}
String temp = "";
String lbl = "TABLE #";
int num = 10,
rowLength = 10,
colLength = 3;
int tableNumber = 1,
counter = colLength,
index = 1;
for ( int colLabel = index; colLabel <=num; colLabel++, tableNumber++ ){
System.out.printf("%11s %-10s",lbl + tableNumber, "");
if ( colLabel == counter || colLabel == num ){
System.out.println();
for ( int row = 1; row <=rowLength; row++){
for ( int column = index; column <=colLabel; column++){
temp = String.format("%4d x %-3d= ", column, row );
temp += String.format("%-10d",(column * row));
System.out.printf("%20s",temp);
}
System.out.println();
// temp = "";
}
System.out.println("\n");
index = (tableNumber + 1);
counter += colLength;
}
}