Scala编写的打印乘法口诀和金字塔

   刚开始接触scala,觉得语法简单,一时兴起就写了两个简单的例子
public class Calculate {
public static void test1(){
for(int i=1;i<10;i++){
for(int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+i*j+" ");
}
System.out.println();
}
}
public static void test2(){
int i=1;
while(i<10){
int j=1;
while(j<=i){
System.out.print(j+"*"+i+"="+i*j+" ");
j++;
}
System.out.println();
i++;
}
}
     public static void main(String[] args) {
    test1();
    test2();
}
}

 

public class Pyramid {
public static void open(int k){
for(int i=1;i<=k;i++){
for(int j=1;j<=k-i;j++){
System.out.print(" ");
}
for(int j=1;j<=i;j++){
System.out.print("* ");
}
System.out.println();
}
}

public static void main(String[] args) {
open(9);
}

}

 

posted @ 2016-07-04 16:39    阅读(1074)  评论(0编辑  收藏  举报