JAVA使用for循环打印三角形

Java利用for循环,打印输出实心、空心三角形 for(int i = 1; i <= 5; i++){ //控制打印的行数 for(int j = 0; j < i; j++){ //控制每行打印的个数 System.out.print("*"); } System.out.println(); //换行 } for(int i = 5; i >= 1; i--){ //控制打印的行数 ... 阅读详情
public class Sanjiaoxing {
public static void main(String []args){
System.out.println("请输出一个三角形");
for (int i = 0; i < 10; i++) {

for (int j = 0; j <= 8-i; j++) {
System.out.print(" ");
}
for (int k = 0; k <= i; k++) {
System.out.print("* ");
}
System.out.println("  ");
}
}

}

请输出一个三角形
         *   
        * *   
       * * *   
      * * * *   
     * * * * *   
    * * * * * *   
   * * * * * * *   
  * * * * * * * *   
 * * * * * * * * *   
* * * * * * * * * *   


java中的for循环的嵌套(实现打印正三角形效果) 运行效果: 一、 for循环嵌套和正方形对角线 说明: 上面的两种方式使用for循环的嵌套(主要是内循环的循环条件的不同)最后的效果都是生成一个正方形。 但是我们知道正方形有两个对角线,在java中我们可以通过内循环的控制是范对角线还是正对角线。 快速判断正方向的对角线走向,同时看外循环和内循环的第一个值: 如果是 for (int i=1; ){ for(int j=1; ) } 说明就是就是反对角线(此时对应的是左上角) 如果是 for(int i=1; 阅读详情

相关推荐

最新Linux CSI Tools安装教程(两台主机,一发一收)(监控模式)

无线感知之CSI Tools工具安装,最新在监控模式下采集CSI数据,

h1998040218的博客 3033

for循环之打印三角形

知识点 一.直角三角形(左上左下右上右下,都有图) 1.1打印直角三角形(左上) /**打印直角三角形 * ** *** **** ***** 如上图 */ class DemoXing2 { public static void main(String[] args) { //打印行数row for(int row=1;row<=5;row++){ //打印星星 for(int star=0;star <row ;star++){ Syst

qq_64436320的博客 6618

CloudSat卫星数据高效下载与自动化处理指南

本文详细介绍了CloudSat卫星数据的高效下载与自动化处理方法,包括交互式图形界面和wget批量下载技巧,以及使用Python脚本实现自动化处理和数据质量控制。内容涵盖从数据准备到实战应用的完整流程,特别适合气象研究和气候建模领域的工作者提升工作效率。

weixin_28700411的博客 233

Java流程控制:用for循环打印一个三角形

用for循环打印一个三角形

pxqwyy1024的博客 2396

从零构建:用Simulink搭建固定翼无人机六自由度模型的避坑指南

本文详细介绍了使用Simulink从零构建固定翼无人机六自由度动力学模型的完整流程和避坑指南。重点解析了模型架构设计、气动力计算、参数配置、仿真求解器选择等关键环节的常见问题与解决方案,帮助开发者快速建立准确可靠的无人机控制系统仿真模型。

hhh00的博客 999

实战经验:Sensor Bringup中那些坑我都帮你踩过了(避坑指南)

本文是一份详尽的Sensor Bringup实战避坑指南,总结了从I2C通信、MCLK时钟、电源管理到图像异常等关键环节的常见问题与排查方法。文章提供了系统化的调试工作流,强调先硬件后软件的排查原则,旨在帮助硬件工程师快速定位并解决Sensor启动过程中的难题,提升开发效率。

weixin_29212429的博客 574

用for循环语句打印三角形

for循环语句打印正、倒三角形;

qq_45537062的博客 3229

WRF替换静态地理数据中的土地利用数据(WRF替换下垫面数据)

   在进行自己的WRF项目模拟的时候,因为需要用中国土地利用数据替换WRF内嵌老旧的土地利用数据,故需要将土地利用进行替换。我使用的中国的土地利用数据是来自中国土地利用数据(1980-2015)。其中我以下载的lucc1980为例进行演示。 1、坐标转换    (1)下载的lucc1980数据如下图所示:    (2)在ArcMap中打开如下图所示: 打开属性表可以看到,lucc1980的坐标系为投影坐标系Krasovsky_1940_Albers,数据格式为GRID。这里需要将投影坐标系转换成地理坐

GIS 1万+

Java循环——打印九九乘法表、正三角、倒三角、菱形

【代码】Java循环——打印九九乘法表、正三角、倒三角、菱形。

Nicole_d的博客 767

Gromacs实战:从蛋白质-小分子对接到分子动力学模拟全流程解析

本文详细解析了使用Gromacs进行蛋白质-小分子复合物分子动力学模拟的全流程。从处理AutoDock等对接软件的结果文件开始,逐步指导如何为蛋白质和小分子分别生成拓扑文件,并解决力场合并的核心挑战。文章涵盖了构建模拟盒子、添加溶剂离子、能量最小化、平衡模拟以及关键的轨迹分析步骤,为计算生物学和药物设计研究者提供了一套从静态对接到动态评估的完整实战指南。

weixin_29251337的博客 1219

ctle电路求帮忙分析低中高频调节原理,搭好了电路该怎样调节参数?

🏆本文收录于专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家!持续更新中,up!up!up!!

**My Coding Family** 1127

Java用for循环打印三角形菱形

java用for循环打印直角三角形,菱形,等腰三角形,平行四边形等

HAN&BLOG 3747

GEE生物量预测:利用多源遥感数据和随机森林算法RF构建地上生物量(AGB)预测模型,并实现未来年份的生态变化模拟(大面积生物量反演)

数据融合策略:整合5类遥感产品(AGB、NDVI、LAI、土地覆盖、地形)时序特征构建:采用生长季中值法降低云污染影响机器学习优化分层采样保证数据代表性80棵决策树平衡精度与效率预测可靠性基准期R²达0.76需结合地面实测数据校正。

此星光明博客 419

java基础之使用for循环打印三角形

最终效果 实现 如果不使用for循环,我们可以这样实现 System.out.println("*"); System.out.println("**"); System.out.println("***"); System.out.println("****"); 这里的ln具有换行作用这个大家都知道哈,那么我们要用for循环的话该如何做呢? 首先想到的是这样 for(int i=0...

Peng_C的博客 2084

深度学习工具包 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")

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

java for 循环打印 三角形

问题使用for 打印一个三角形如图 思路:将其分为3部分打印如图 代码如下 package xyz.for循环的3个作业; public class triangle { //打印一个三角形triangle public static void main(String[] args) { for (int i = 1; i <= 5; i++) { ...

半亩方糖 2554

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

java中使用for循环打印三角形

java中使用for循环打印三角形 (1)打印一个左直角三角形 import java.util.Scanner; public class Triangle { public static void main(String[] args) { //打印一个左直角三角形; Scanner input=new Scanner(System.in); System.out.print("请输入三角形的行数:"); int row=input.nextInt(); for(int i=0;i<ro

weixin_45669016的博客 5383

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

java使用for循环打印三角形

使用for循环打印三角形 package struct; /** * @author 吴某人 * @PackageName:struct * @ClassName:TextDemo01 * @Description: 打印三角形 * @date 2020/8/14 001416:40 */ public class TextDemo01 { public static void main(String[] args) { //打印三角形 5行 for(

qq_46867640的博客 1340

Java用for循环打印正三角形和倒三角形

public class Test05 { public static void main(String[] args) { // 在这里打印出正三角形 for (int i = 1; i <= 10; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out....

weixin_45654215的博客 6812

Java for循环打印三角形

Java for循环打印三角形 package com.struct; ​ public class TestDemo01 { public static void main(String[] args) { //打印三角形 for (int i = 1; i <= 5; i++) { for (int j = 5; j >= i; j--) { System.out.print(" "); ...

Charsir的博客 427

Java利用for循环打印各种图形:正三角形、倒三角形、正等腰三角形、倒等腰三角形和菱形

打印各种三角形 打印水仙花数 打印九九乘法表 读入一个整数(行数),用*打印正三角形、倒三角形、正等腰三角形、倒等腰三角形和菱形(for循环) import java.util.Scanner; public class TestGraphics { public static void main(String[] args) { Scanner sc = new Scanner(S...

奈何的人生 9431

Java打印三角形(双层for循环)

Java打印三角形(双层for循环) 1.第一个三角形: 打印样式: 外层for循环控制行数,内层for循环控制“*”的个数 public static void demo01(){ //行数:4行 for(int i=1;i<=4;i++){ /* 找规律: 第一行:1个* 第二行:3个* 第三行:5个* 第四行:7个* *

淼的博客 3867

java打印直角三角形,for循环嵌套

1.打印直角三角形(靠左) 2.打印直角三角性(靠右)

菜鸟一梦 8417

【Java】for循环打印三角形

for循环打印三角形

Jack 1000

Java双重for循环打印三角形

【代码】Java双重for循环打印三角形。

z1561599530b的博客 728

java打印三角形,空心,for循环嵌套

1.等腰三角形(空心) 2.直角三角形(空心)

菜鸟一梦 1万+

Java中使用for循环打印直角三角形,倒立直角三角形,等腰三角形,平行四边形,菱形等

1.打印正直角三角形 package javacto.taobao.com; public class TestFor { public static void main(String[] args) { //package for(int i=1;i<=10;i++){ for(int j=1;j<=i;j++){ System.out.print("*"); }

曾昭武 8225
上一篇: “用户需求”之“切入需求”
下一篇: JAVA打印九九乘法表
风暴search
博客等级 码龄14年 28粉丝 53原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值