zoukankan      html  css  js  c++  java
  • JAVA基础:求一个等腰三角形

    import java.util.Scanner;

    public class text {
     public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      System.out.println("请输入一个等腰三角形的高:");
      int height = scan.nextInt();
      for (int j = 1; j <= height; j++) {
       for (int i = 0; i < height - j; i++) {
        System.out.print("0");
       }
       for (int i = 0; i < (2 * j - 1); i++) {
        System.out.print("*");
       }
       System.out.println();
      }
     }
    }

    //求一个等边三角形的*

    import java.util.Scanner;

    public class P7 {
     public static void main(String[] args) {
      System.out.println("请输入一个三角形的高:");
      Scanner scanner=new Scanner(System.in);
      int number=scanner.nextInt();
      for(int i=1;i<number;i++){
       for(int space=1;space<=number-i-1;space++){
        System.out.print(" ");
       }
       for(int star=1;star<=i;star++){
        System.out.print("*"+" ");
       }
      System.out.println("");
     }
    }
    }

  • 相关阅读:
    Tarjan 算法 自学整理
    POJ 2395 Out of Hay
    Codevs 1557 热浪
    Codevs 2956 排队问题
    Codevs 1005 生日礼物
    集合
    奇怪的函数
    关押罪犯
    搭积木
    大数据
  • 原文地址:https://www.cnblogs.com/smile-zcc/p/5554903.html
Copyright © 2011-2022 走看看