1 //1. Diamond2 Public Static voidLingxing (intsize) {3 if(size% 2 = = 0){4size++;//Calculate Diamond Size5 }6 //top half of the output diamond7 for(inti = 0; I < SIZE/2 + 1; i++) {8 for(intj = size/2 + 1; J > i + 1; j--) {9System.out.print ("");//white space at the top left corner of the outputTen } One for(intj = 0; J < 2*i + 1; J + +) { ASystem.out.print ("*");//top half of the output diamond - } -System.out.println ();//line Break the } - //output diamond Lower half - for(inti = SIZE/2 + 1; i < size; i++) { - for(intj = 0; J < I-SIZE/2; J + +) { +System.out.print ("");//output diamond lower left corner blank - } + for(intj = 0; J < 2*size-1-2*i; J + +) { ASystem.out.print ("*");//output diamond Lower half at } - System.out.println (); - } - } - - //2.99 Multiplication Table in Public Static voidmultiplicationtable () { - for(inti = 1; I <= 9; i++) { to for(intj = 1; J <= I; J + +) { +System.out.print (j+ "x" +i+ "=" +i*j+ "\ t");//\ t jumps to the next tab position - } theSystem.out.println (""); * } $ }Panax Notoginseng - //3. Printing triangles the Public Static voidTriangle (intN) { + for(inti = 0; I <= N; i++) { A for(intj = N; J >= I; j--) { theSystem.out.print ("");//set up number 1th graphics + } - for(intj = 1; J <= I; J + +) { $System.out.print ("*");//set up number 2nd graphics $ } - for(intj = 1; J < I; J + +) { -System.out.print ("*");//set up number 3rd graphics the } -System.out.println ("");Wuyi } the } - Wu //4. Print inverted triangles - Public Static voidInvertedtriangle (inti) { About //Print a inverted triangle $ for(intm = 1; M <= i; m++) { - //Print Space - for(intn = 0; n <= m; n++) { -System.out.print (""); A } + //Print * the for(intx = 1; x <= (I-M) + 1; X + +) { -System.out.print ("*"); $ } the System.out.println (); the } the } the - //5. Print Parallelogram in Public Static voidParallelogram (intN) { the //The outer loop each time a * the for(inti = 1; I <=n; i++) { About //padding Spaces the for(intj = 1; J <= N-i; J + +) { theSystem.out.print (""); the } + //The inner loop prints one at a time * - for(intK = 1; K <=n; k++) { theSystem.out.print ("*");Bayi } the System.out.println (); the } - } - the //6. Print Parallelogram the Public Static voidRectangle (intN) { the //The outer loop each time a * the for(inti = 1; I <=n; i++) { - //Outer loop output one line at a time * theSystem.out.print ("*"); the the //The inner loop prints one at a time *94 for(intK = 1; K <=n; k++) { theSystem.out.print ("*"); the } the System.out.println ();98 } About}
Java Learning Notes (iv)---print graphics