用java编一到程序
来源:百度知道 编辑:UC知道 时间:2024/05/13 22:47:36
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10
如图 谢谢了
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10
如图 谢谢了
class TestNum
{
public static void main(String[] s)
{
for (int i = 1; i <= 10; i++)
{
for(int k=1;k<=i;k++)
{
System.out.print(i +" ");
}
System.out.println();
}
}
}
// 你看看以下代码,直接运行这个代码就可以看到结果了
public class Test {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
System.out.println(repeat(String.valueOf(i), i));
}
}
private static String repeat(String str, int num) {
String returnStr = "";
for (int i = 0; i < num; i++) {
returnStr += str + " ";
}
return returnStr;
}
}
和九九乘法表一样。