Home >Java >javaTutorial >Share the implementation code for printing simple graphics in java

Share the implementation code for printing simple graphics in java

高洛峰
高洛峰Original
2017-01-17 16:26:491368browse

We usually use drawing tools to draw simple graphics. Today we use java to print some simple graphics

The implementation code is as follows

package test;
/**
 *
 * @author hanzel
 * @打印图形
 *
 */
public class Array {
  public static void main(String[] args) {
    //打印长方形
    int[] a = new int[10];
    for(int i=0 ;i<a.length;i++){
      for(int j=0;j<a.length;j++){
        System.out.print("*");
      }
    System.out.println();
    }
    System.out.println();
     
    //打印倒直角三角形
    int[] b = new int[10];
    for(int i=0 ;i<b.length;i++){
      for(int j=0;j<b.length-i;j++){
        System.out.print("*");
      }
    System.out.println();
    }
    System.out.println();
     
    //另一种倒直角三角形
    int[] e = new int[10];
    for(int i=0;i<e.length;i++){
      for(int j=0;j<i;j++){
        System.out.print(" ");       
      }
      for(int m=0;m<e.length-i;m++){
        System.out.print("*");
      } 
    System.out.println();
    }
    System.out.println();
     
    //打印出平行四边形
    int[] c = new int[10];
    for(int i=0;i<c.length;i++){
      for(int j=0;j<i;j++){
        System.out.print(" ");       
      }
      for(int m=0;m<c.length;m++){
        System.out.print("*");
      } 
    System.out.println();
    }
    System.out.println();
     
    //另一种平行四边形
    int[] h = new int[10];
    for(int i=0 ;i<h.length;i++){
      for(int j=0;j<h.length-i;j++){
        System.out.print(" ");       
      }
      for(int m=0; m<h.length;m++){
        System.out.print("*");
      }
    System.out.println();
    }
    System.out.println();
     
    //打印正直角三角形
    int[] d = new int[10];
    for(int i=0;i<d.length;i++){
      for(int j=0;j<i;j++){
        System.out.print("*");       
      }
    System.out.println();
    }
    System.out.println();
     
    //打印另一种正直角三角形
    int[] f = new int[10];
    for(int i=0;i<f.length;i++){
      for(int j=0;j<f.length-i;j++){
        System.out.print(" ");   
      }
      for(int m=0;m<i;m++){
        System.out.print("*");   
      }
    System.out.println();
    }
    System.out.println(); 
     
     
    //打印出直角梯形
    int[] g = new int[10];
    for(int i=0;i<g.length;i++){
      for(int j=0;j<g.length;j++){
        System.out.print("*");       
      }
      for(int m=0;m<i;m++){
        System.out.print("*");
      } 
    System.out.println();
    }
    System.out.println();
 
    //等腰三角形
    int[] k = new int[10];
    for(int i=0;i<k.length;i++){
      for(int j=0;j<k.length-i;j++){
        System.out.print(" ");   
      }
      for(int m=0;m<2*(i+1)-1;m++){
        System.out.print("*");   
      }
    System.out.println();
    }
    System.out.println();
    //另一种等腰三角形
    int[] l = new int[10];
    for(int i=0;i<l.length;i++){
      for(int j=0;j<i;j++){
        System.out.print(" ");       
      }
      for(int m=0;m<2*(l.length-i)-1;m++){
        System.out.print("*");
      } 
    System.out.println();
    }
    System.out.println(); 
   
    //菱形
    int[] o = new int[10];
    for(int i=0;i<o.length;i++){
      for(int j=0;j<o.length-i;j++){
        System.out.print(" ");   
      }
      for(int m=0;m<2*i-1;m++){
        System.out.print("*");   
      }
      System.out.println();
    }
    for(int i=0;i<o.length;i++){
      for(int j=0;j<i;j++){
        System.out.print(" ");       
      }
      for(int m=0;m<2*(o.length-i)-1;m++){
        System.out.print("*");
      } 
      System.out.println();
    }
  }
}

The above is the entire content of this article. This small program has strong versatility and I hope it will be helpful to everyone's learning.

For more articles related to sharing the implementation code of java printing simple graphics, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn