用for循环语句打印以下直角三角形
        *
     * *
   * * *
 * * * *

解决方案 »

  1.   

    public class RightAngle {
    public static void main (String args[]) {
    rightAngle(4);
    }

    private static void rightAngle (int n) {
    String s = "*";
    String t = " ";

    for (int i=1;i<=n;i++) {
    for (int j=i-1;j<i;j++) {
    for (int k=n-i;k>0;k--) {
    System.out.print(t);
    }
    System.out.println(s);
    s+="*";
    }
    }
    }
    }
      

  2.   

    直角三角形1
    *
    * * 
    * * *
    * * * *public class PrintTriangle{
    public static void main(String[] args){
    for(int i=0;i<4;i++){
    for(int j=0;j<=i;j++){
    System.out.print("* ");
    }
    System.out.println();
    }
    }
    }直角三角形2
          *
        * *
      * * *
    * * * *public class PrintTriangle{
    public static void main(String[] args){
    int i;
    int j;
    for(i=0;i<4;i++){
    for(j=3;j>i;j--){
    System.out.print("  ");
    }
    for(j=i;j>=0;j--){
    System.out.print("* ");
    }
    System.out.println();
    }
    }不知道你说的是哪一种情况,都给出来了
      

  3.   

    直角三角形1
    *
    * * 
    * * *
    * * * *public class PrintTriangle{
    public static void main(String[] args){
    for(int i=0;i<4;i++){
    for(int j=0;j<=i;j++){
    System.out.print("* ");
    }
    System.out.println();
    }
    }
    }直角三角形2
          *
        * *
      * * *
    * * * *public class PrintTriangle{
    public static void main(String[] args){
    int i;
    int j;
    for(i=0;i<4;i++){
    for(j=3;j>i;j--){
    System.out.print("  ");
    }
    for(j=i;j>=0;j--){
    System.out.print("* ");
    }
    System.out.println();
    }
    }不知道你说的是哪一种情况,都给出来了