首页 > 编程语言 > 详细

JAVA基础:求一个等腰三角形

时间:2016-06-03 01:13:59      阅读:216      评论:0      收藏:0      [点我收藏+]

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("");
 }
}
}

JAVA基础:求一个等腰三角形

原文:http://www.cnblogs.com/smile-zcc/p/5554903.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!