打印任意尺寸等腰和等边三角形

等腰三角形打印 自己写的。 关于等腰三角形的打印。 没理清自己的思路,一步一步改过来的。 立即下载

老有人问这个初级的问题,做了这个支持任何底边和高度的打印程序。留作参考。
  1. class T {
  2.   public static void main(String[] args) {
  3.     printDengYao(20, 10);// 打印等腰三角形
  4.     printDengBian(20);
  5.   }

  6.   public static void printDengBian(int width) {
  7.     // 等边三角形,需要先计算
  8.     printDengYao(width, (int) (Math.tan(60.0 / 180.0 * Math.PI) * width / 2));
  9.   }

  10.   /**
  11.    * 等腰三角形。
  12.    * 
  13.    * @param width
  14.    *          底边宽度,最好是偶数。
  15.    * @param height
  16.    *          高度
  17.    */
  18.   public static void printDengYao(int width, int height) {
  19.     // 中点位置,也是第一个点的位置
  20.     int middle = (width + 1) / 2;
  21.     // 开始打印的位置
  22.     int start;
  23.     // 终止打印的位置
  24.     int end;
  25.     // 角度
  26.     double angle = 1.0 * middle / height;
  27.     for (int k = 0; k <= height; k++) {
  28.       start = (int) (middle - k * angle);
  29.       end = (int) (middle + k * angle);
  30.       for (int m = 0; m <= start; m++) {
  31.         System.out.print(" ");
  32.       }
  33.       for (int m = start; m <= end; m++) {
  34.         System.out.print("*");
  35.       }
  36.       System.out.println();
  37.     }
  38.   }
  39. }

 
运行效果

[arcgis插件]在批量出图时,如何把图层属性表以动态表格的形式插入到布局页面 在批量出图时,如何把图层属性表以动态表格的形式插入到布局页面。 阅读详情

相关推荐

无耳科技 Solon v3.0.8 发布,Java 企业级应用开发框架

Solon 是新一代,Java 企业级应用开发框架。是杭州无耳科技有限公司的“根级”开源项目(最近“杭州六小龙”很火啊,我们也是杭州的哦)。从零开始构建(No Spring、No Java-EE、No Servlet),有灵活的接口规范与开放生态。采用对商用友好的 Apache 2.0 开源协议。

向往自由的少年!(我是一个少年!!!) 1700

java打印任意高度的三角形

我们是把一个三角形分成三部分: 首先打印三角形左边空白 其次打印中间左半边的三角形 最后打印右半边的三角形 你可以选择打印任意高度的三角形! 代码如下: package com.xiaoye.scanner; import java.util.Scanner; public class 三角形 { public static void main(String[] args) { // 打印三角形 System.out.println("请输入你要打印三角形的行

yezhihui520的博客 503

LQR控制算法调参指南:如何通过Bryson‘s Rule和Trial-and-Error优化自动驾驶性能?

本文深入探讨了LQR控制算法在自动驾驶系统中的调参策略,从Bryson's Rule的基础应用到工程落地的优化方法。通过动态权重适应、非对角项引入和多目标权衡等技巧,提升车辆轨迹跟踪精度与操控舒适性。文章还介绍了数据驱动的调参流程和典型问题的解决方案,为自动驾驶工程师提供实用指南。

kkk56的博客 1026

java打印三角形,菱形。任意边长大小

一、等腰三角形          for (int j = 0; j &lt; num; j++) {             if (j &gt; 0) {                 for (int i = 0; i &lt; j; i++) {                     if (i == j - 1) {                         for (...

meixi_android的博客 1024

Windows非分页缓冲池内存泄漏实战:PoolMon与RAMMap高效排查指南

本文详细介绍了Windows系统中非分页缓冲池内存泄漏的实战排查方法。当系统出现卡顿且内存占用异常增长时,通过RAMMap工具快速定位非分页缓冲池异常,并利用PoolMon监控内核内存分配标签,精准锁定泄漏源。文章提供了从确认症状、安装工具到使用findstr命令溯源驱动文件的完整五步排查流程,并总结了常见泄漏标签与解决方案,帮助用户高效解决深层系统内存问题。

weixin_28455801的博客 1012

Jetson Nano摄像头选型与配置全攻略:CSI与USB接口实战指南

在嵌入式视觉与边缘计算项目中,摄像头作为核心传感器,其选型与配置直接影响系统性能。CSI(Camera Serial Interface)和USB(Universal Serial Bus)是两种主流接口,前者通过MIPI CSI-2协议直接与SoC通信,具备低延迟、高带宽特性,适合实时性要求高的应用;后者基于通用串行总线标准,即插即用,通用性强。在NVIDIA Jetson Nano平台上,合理选择摄像头接口并优化驱动配置,能充分发挥其GPU加速优势,提升图像处理流水线效率。本文聚焦Jetson Nano

weixin_29190651的博客 323

打印任意层数的杨辉三角形

public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("输出n层杨辉三角形,n="); int n = sc.nextInt(); int[][] a = new int[n + 1][n + 1];//创建一个(n+1)*(n+1)的数组 //第1行第2个元素(第1行第1个也可以)赋值为1(或者其他数),这个元素不参与输出,属于初值

imherelux的博客 579

6、基于深度强化学习的无人机路径规划

本文介绍了一种结合人工势场法的改进DQN深度强化学习算法在无人机路径规划中的应用。通过设计合理的网络结构、状态空间、动作空间和融合引力-斥力机制的奖励函数,实现了无人机在复杂环境中的自主避障与目标导向飞行。采用轻量级神经网络提升实时性,并在Gazebo仿真环境中进行训练与测试,结果表明该算法具有快速收敛、高成功率和良好适应性。实验评估指标包括损失函数、最大Q值和任务成功率,验证了方法的有效性。文章还探讨了其在物流配送、农业植保和环境监测等领域的应用前景,并展望了多无人机协同与复杂环境适应性等未来研究方向。

html8的博客 242

python_实现打印高度为n的等腰三角形

实现一个函数,输入整数n,可以打印高度为n的等腰三角形. 样例: n = 4 ,打印的三角形为: * * * * * * * * * * * * * * * def func(n): for x in range(1,n+1): m = x * "* " print(m.center(n*2)) func(...

cwy0502的博客 4703

STM32F103C8T6驱动DHT11温湿度传感器程序

本程序基于 STM32F103C8T6 微控制器,通过 GPIO 模拟单总线通信时序实现对 DHT11 温湿度传感器的数据采集,主机采用拉低数据线的方式触发传感器启动,并通过检测高电平持续时间区分逻辑“0”和“1”,依次读取湿度和温度的整数数据及校验位,经过校验后将有效结果存入缓存数组,实现对环境温湿度的周期性测量与处理。

加斯顿工程师的博客 201

汽车OTA 测试用例

汽车OTA 测试用例

天赐好车的博客 976

python练习题(十八):打印出指定高度的菱形

# 题目:打印出指定高度的菱形 while True: height = int(input("指定菱形高度(请输入一个大于1的奇数):")) if height <= 1 or height % 2 == 0: print("请输入一个大于1的奇数!") else: width_list = [1] # 用列表存放菱形每层的...

biubiusion的博客 1027

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Java打印任意行数等腰三角形

Java打印任意行数等腰三角形 public static void main(String[] args) { Scanner input= new Scanner(System.in); System.out.println("请输入行数"); int n=input.nextInt(); f1(n); } static void f1(int n) { ...

颜文宇的博客 1666

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java打印输出任意大小的等腰三角形,实心菱形,空心菱形,平行四边形

import java.util.Scanner; public class PrintShape { public static void main(String[] args) { Scanner sc= new Scanner(System.in); boolean flag= true;//设置值为true,进入循环 int row= 0; int choice= 0;...

qq_40755869的博客 937

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

最简单打印三角形方法

      程序的源代码如下:import java.applet.*; import java.awt.*; public class Applet1 extends Applet {   public void paint(Graphics g)     {      int i=1,j,n=5;       while(i           {                     

liuh520的专栏 2333

按要求打印三角形和菱形

   1.任意输入一个数n代表三角形的高度,打印此形状的三角形     如:      请输入: 4         1        121       12321      1234321   2.将第三题打印三角形变为打印棱形         1        121       12321      1234321         12321         121          1 ...

FFAIzero的博客 866

(C语言打印图形题4)编程,输入n,输出如下例(n=4)所示的高为n的倒立等腰三角形。

编程,输入n,输出如下例(n=4)所示的高为n的等腰三角形。          *******            *****             ***              *              解答: 1. 程序截图: 2. 程序源码: #include int main(int argc, char *argv[]) { //输出高

婧萱 1万+

打印三角形

一个简单的三角形题目,可以学到很多。

亮晶晶的博客 730

c语言编程输出等腰三角形,C语言输出等腰三角形

本实例要求从键盘输入任意整数 n,通过程序运行输出对应高度为 n 的等腰三角形。算法思想① 设计以高度 n 为参数的一个函数,函数返回值为空,在函数体中实现等腰三角形的打印;图形的最终打印需要利用二层循环设计实现。② 图形共输出 n 行,外循环变量 i 表示 n 行的输出,循环变量的变化范围为 0~(n—1)。③ 循环变量 j 表示每一行的“*”号输出。由于每一行的输出不同,第 j 行输出空格的个...

weixin_28932365的博客 9656

打印出等腰三角形

第一步:输出正方形 &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &amp; &a

zs_66666的博客 379

Java输出自定义高度的三角形

之前在《用python和Java打印三角形和阶梯》一文中讲过如果用Java打印三角形;现在来看看如何用Java输出自定义高度的三角形:

number1killer的博客 1008

打印图形三角形(等腰三角形与直角三角形)

打印等腰三角形 * *** ***** ******* ********* 若打印上面的等腰三角形,首先要分析规律 设打印n行的三角形(以打印5行为例) 第一行 4个空格=5-1 1个“*”=2*行数-1 第二行 3个空格=5-2 3个“*”=2*行数-1 第三行 2个空格=5-3 5个“*”=2*行数-1 第四行 1个...

hey,欢迎浏览我的博客,希望能给你提供帮助。 1253

刚学编程的时候做的一些逻辑练习题

//1.计算1—100之和 int sum = 0; for (int i = 1; i&amp;lt; 101; i++) { sum += i; } Console.WriteLine(sum); //2.计算1—100所有偶数之和(使用do while实现) int sum = 0; int count = 1; ...

qq_34422961的博客 1772
上一篇: JVM和JRE,JDK的关系
下一篇: 一个JAVA图形缩放处理工具类
老紫竹
博客等级 码龄19年 1万+粉丝 1252原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值