1. Printing graphics with double cycle 1
public class fivetest{
public static void Main (string[] args) {
for (int i=1;i<=4;i++) {
--spaces for each line
for (int k=1;k<= (4-i); k++) {
System.out.print ("");
}
--Print * number
for (int j=1;j<= (2*i-1); j + +) {
System.out.print ("*");
}
--line break
System.out.println ();
}
} }
2. Printing graphics with double cycle 1
public class test5{
public static void Main (String [] args) {
int count=3;
for (int i=1;i<8;i+=2) {
for (int k=count;k>0;k--) {
System.out.print ("");
}
count--;
for (int j=1;j<=i;j++) {
System.out.print ("*");
}
System.out.println ();
}
} }
3. Printing graphics with double Cycle 2
public class sixtest{
public static void Main (string[] args) {
/*
Divide the topic into two parts to solve
*/
-1, Upper Triangle
for (int i=1;i<=4;i++) {
--spaces for each line
for (int k=1;k<= (4-i); k++) {
System.out.print ("");
}
--Print * number
for (int j=1;j<= (2*i-1); j + +) {
System.out.print ("*");
}
--line break
System.out.println ();
}
-2, Lower triangle
for (int i=3;i>=1;i--) {
--Print spaces
1 2 3
for (int w=3;w>=i;w--) {
System.out.print ("");
}
--Print * number
1 2 3) 4 5
for (int j=1;j<= (2*i-1); j + +) {
System.out.print ("*");
}
--line break
System.out.println ();
}
}
}
4. Printing graphics with double Cycle 2
public class Test66
{
public static void Main (string[] args)
{
for (int i = 1; I <= 7; i++)
{
if (I <= 4)
{
for (int m = 1; M <= 5-i; m++)
{
System.out.print (""); Print space required for each line
}
for (int n = 1; n <= 2 * i-1; n++)
{
System.out.print ("*"); Print "*" for each line that should be printed
}
System.out.println ();
}
Else
{
for (int x = 1; <= i-3; x + +)
{
System.out.print (""); Print space required for each line
}
for (int y = 1; y <= 15-2 * i; y++)
{
System.out.print ("*"); Print "*" for each line that should be printed
}
System.out.println ();
}
}
}
}
5. Printing graphics with double Cycle 2
public class test6{
public static void Main (String [] args) {
int count=3;
int count1=1;
for (int i=1;i<8;i+=2) {
for (int k=count;k>0;k--) {
System.out.print ("");
}
count--;
for (int j=1;j<=i;j++) {
System.out.print ("*");
}
System.out.println ();
}
for (int i=5;i>0;i-=2) {
for (int k=1;k<=count1;k++) {
if (count1>3) {break;}
System.out.print ("");
}
count1++;
for (int j=1;j<=i;j++) {
System.out.print ("*");
}
System.out.println ();
}
} }
6, combined with two-bit array printing Yang Hui triangle, the number of lines printed by the keyboard input
Features of the Yang Hui triangle:
1,) The first element of each line and the last element are 1
2,) The value of the other element is: the element above him + the upper left element
Import Java.util.Scanner;
public class firsttest{
public static void Main (string[] args) {
--Get keyboard input data:
System.out.print ("Please enter the number of lines printed:");
Scanner scan = new Scanner (system.in);
int row = Scan.nextint ();
--defining a two-dimensional array
int[][] arr = new Int[row][row];
for (int i=0;i<arr.length;i++) {
for (int j=0;j<=i;j++) {
if (j==0| | J==i) {
ARR[I][J] = 1;
}else{
ARR[I][J] = Arr[i-1][j] + arr[i-1][j-1];
}
}
}
--traversing elements in a two-dimensional array
for (int i=0;i<arr.length;i++) {
-Print spaces
for (int k=1;k<row-i;k++) {
System.out.print ("");
}
for (int j=0;j<=i;j++) {
System.out.print (arr[i][j]+ "");
}
System.out.println ();
}
}
}
Java applet 1 (2015-8-27)