scala实现菱形打印

package util.scanner

\\scala 实现菱形打印

Object LinXinTest{

def main(args: Array[String]) {
 //上半部分
for(i<-1 to 5;temp=2*i-1;j<-1 to temp){
      print(" ")
      if(j==temp)println()
    }
    var x=7
    for(a <-1 to x by 2){
      for(b <- x to a-1 by -2){
        print(" ")
      }
      for(c<-1 to a){
        print("*")
      }
      print("\n")
    }
//下半部分

  var y= x-2
    for(a<-1 to y by 2){
      print(" ")
      for(b<-1 to a by 2){
        print(" ")
      }
        for(c <-y to a by -1){
          print("*")
        }
      print("\n")
    }
}
}

你可能感兴趣的:(scala实现菱形打印)