Java for版本
public class test1 { public static void five(int n){ for (int i =1;i<=n;i++){ for (int j =1;j<=i;j++){ System.out.print(i+"×"+j+"="+i*j+" "); } System.out.print("n"); } } public static void main(String[] args) { five(9); } }
结果
Java while版本
public class test1 { public static void five(int n){ int i =1; while (i<=n){ int j =1; while (j<=i){ System.out.print(i+"×"+j+"="+i*j+" "); j++; } i++; System.out.print("n"); } } public static void main(String[] args) { five(9); } }
结果:
Python for版本:
def five(n): for i in range(1, n+1): for j in range(1, i + 1): print(str(i) + "×" + str(j) + "=" + str(i * j), end=" ") print() five(9)
结果:
Python while版本:
def five(n): i = 1 while i <= 9: j = 1 while j <= i: print(str(i) + "×" + str(j) + "=" + str(i * j), end=" ") j += 1 print() i += 1 five(9)
结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)