zoukankan      html  css  js  c++  java
  • java 打印图形

    打印菱形

    package study.stage2;

    /**
    * Created by Sandy.Liu on 2017/7/27.
    */
    public class Diamond {
    public static void main(String[] args){
    print(8);
    }

    public static void print(int size){
    if(size%2==0){
    size++;
    }

    for(int i=0;i<size/2+1;i++){
    for(int j=size/2+1;j>i+1;j--){
    System.out.print(" ");
    }

    for(int j=0;j<2*i+1;j++){
    System.out.print("*");
    }
    System.out.println();
    }
    for(int i=size/2+1;i<size;i++){
    for(int j=0;j<i-size/2;j++){
    System.out.print(" ");
    }
    for(int j=0;j<2*(size-i)-1;j++){
    System.out.print("*");
    }
    System.out.println();
    }
    }
    }


    打印乘法表
    package study.stage2;

    /**
    * Created by Sandy.Liu on 2017/7/27.
    */
    public class MotiplicationTab {
    public static void main(String[] args){
    int count = 1;
    for(int i=0;i<9;i++){
    for(int j=1;j<=count;j++){
    System.out.print(j+" x "+count+" = "+j*count+" ");
    }
    count++;
    System.out.println();
    }
    }
    }

    运行结果

    1 x 4 = 4 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16
    1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25
    1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36
    1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49
    1 x 8 = 8 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 7 x 8 = 56 8 x 8 = 64
    1 x 9 = 9 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 6 x 9 = 54 7 x 9 = 63 8 x 9 = 72 9 x 9 = 81

    public class PrintQuadrangle {
    public static void main(String[] args){
    int n=5;
    //打印平行四边形
    for(int i=0;i<n;i++){
    for (int j=0;j<i;j++){
    System.out.print(" ");
    }
    for(int j=0;j<n;j++){
    System.out.print("*");
    }
    System.out.println();
    }

    //打印矩形
    System.out.println();
    for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    System.out.print("*");
    }
    System.out.println();
    }
    }

    }
  • 相关阅读:
    寄生组合式继承
    原型式继承
    js数学方法应用
    arguments.callee
    date日期比较和格式化方法
    转型函数 Boolean()
    javaScript高程第三版读书笔记
    《JavaScript dom 编程艺术》 placeholder占位符IE8兼容办法。
    正确设置网站title、keywords、description(转载)
    理解RESTful架构
  • 原文地址:https://www.cnblogs.com/xiaohai2003ly/p/7246131.html
Copyright © 2011-2022 走看看