java编程使用循环语句打印4个图案,答案如下
package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("Enter the number of line"); int number =input.nextInt(); for(int i=1;i<=number;i++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } System.out.println(""); } } }图案2:package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("Enter the number of line"); int number =input.nextInt(); for(int i=1;i<=number;i++){ for(int j=1;j<=(number-i)+1;j++){ System.out.print(j+" "); } System.out.println(""); } } } 图案3:直接拿5.17的修改下就是了。package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter the number of line"); int number =input.nextInt(); for(int i=1; i<=number; i++) { for(int j=(number-i)*3-1; j>=0; j--) { System.out.print(" "); } for(int j=i; j>=1; j--) { if(j<10) System.out.print(""); else System.out.print(" "); System.out.print(j); } System.out.println(""); } } }图案4:package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter the number of line"); int number =input.nextInt(); for(int i=1; i<=number; i++) { for(int k=1; k<i; k++) { System.out.print(" "); } for(int j=1;j<=(number-i)+1;j++) { if(j<10) System.out.print(""); else System.out.print(" "); System.out.print(j); } System.out.println(""); } } }
页:
[1]