6、Java编程基础:表达式、运算符与赋值操作

Java编程基础:表达式、运算符与赋值操作

1. 表达式与运算符概述

表达式是能够传达值的语句,常见的表达式有数学表达式。例如:

int x = 3;
int y = x;
int z = x * y;

以上三个语句都可视为表达式,它们传达的值可赋给变量。表达式可以是变量、字面量和运算符的任意组合,也可以是方法调用,因为方法可以向调用它的对象或类返回一个值。表达式传达的值称为返回值,可赋给变量并在Java程序中以多种方式使用。

运算符是用于数学函数、某些类型的赋值语句和逻辑比较的特殊符号。

2. 算术运算符

Java中有五种用于基本算术运算的运算符,如下表所示:
| 运算符 | 含义 | 示例 |
| ---- | ---- | ---- |
| + | 加法 | 3 + 4 |
| - | 减法 | 5 - 7 |
| * | 乘法 | 5 * 5 |
| / | 除法 | 14 / 7 |
| % | 取模 | 20 % 7 |

每个运算符需要两个操作数,分别位于运算符两侧。减法运算符也可用于对单个操作数取反,相当于将该操作数乘以 -1。使用除法时需注意处理的数字类型,如果将除法运算结果存储为整数,结果将被截断为下一个较小的整数,因为int数据类型无法处理浮点数。例如,表达式 31 / 9 存储为整数时结果为 3。取模运算符 % 用于产生除法运算的余数,如 31 % 9

相关推荐

【Java编程进阶】运算符与表达式

计算机诞生的初衷是为了进行数学的运算,Java 作为一门计算机编程语言,同样也提供了用于操纵变量的`运算符`来进行数学运算。 我们把用于数据的运算,赋值,比较等的一系列符号称之为运算符。

zhangxia_的博客 1440

Java讲课笔记05:运算符与表达式

1. 掌握Java中各种运算符的使用 2. 掌握如何正确书写Java表达式

howard2005的专栏 4330

Python编程基础05:运算符与表达式

文章目录一、算术运算符1、分类说明表2、注意事项3、案例演示任务1、计算成绩差与平均成绩课堂练习:编程处理带余除法。任务2、打印购物小票 运算符就是专门用于告诉程序执行特定运算或逻辑操作的符号。表达式是指由常量、变量和运算符组成的一个算式。编写程序对数据进行处理,其实处理就是对数据实施各种各样的运算,搞懂运算符与表达式是我们编写程序的基础性工作,本次讲课笔记通过案例讲解各种运算符的用法以及正确书写Python表达式的注意事项。 一、算术运算符 Python中的算术运算符就是用来处理四则运算的符号,也是

howard2005的专栏 3127

5、编程基础:Java 表达式与运算符详解

本博文详细介绍了 Java 编程中的各种运算符及其使用方法,包括算术运算符、赋值运算符、自增自减运算符、比较运算符、逻辑运算符和字符串运算符。同时讲解了表达式的基本概念、运算符的优先级规则以及在实际编程中需要注意的细节问题。通过示例代码和流程图,帮助读者更好地理解和掌握 Java 中运算符的应用。

o9p0q1的博客 130

深入Java赋值操作的探索与实践

Java是一种广泛使用的编程语言,由Sun Microsystems公司在1995年发布。自推出以来,Java因其“一次编写,到处运行”的跨平台特性而广受欢迎。Java的演化经历了多个版本,不断增加了新的特性和改进,包括泛型、Lambda表达式和模块系统等,使其始终保持在现代编程语言的前沿。引用数据类型包括类、接口、数组等。其中,类是面向对象编程中的基本单元。通过new关键字可以创建类的实例。当实例化一个类时,Java虚拟机(JVM)会在堆内存中为新对象分配空间,并调用构造器初始化对象。

weixin_30336531的博客 1064

centos7 python3.12.1 报错 No module named _ssl,坑我几个小时

网上的教程很多,但几乎是无效的,跟着我这教程,可以完美解决。

Amio_的博客 1万+

推荐算法之Thompson(汤普森)采样

如果想理解汤普森采样算法,就必须先熟悉了解贝塔分布。 一、Beta(贝塔)分布 Beta分布是一个定义在[0,1]区间上的连续概率分布族,它有两个正值参数,称为形状参数,一般用α和β表示,Beta分布的概率密度函数形式如下: 这里的Γ表示gamma函数。 Beta分布的均值是: 方差: ...

weixin_30508241的博客 4260

XTDrone——ALOAM与3D激光雷达三维SLAM(处理没有点云和坐标系报错的问题)

本文介绍了XTDrone中配置如何在三维环境中使用A-LOAM算法配合velodyneHDL32激光雷达包括依赖包安装、代码修改和PX4系统配置,以及相关报错细节的注意事项。

weixin_45390670的博客 1333

win10 运行lisflood_8踩过的坑

1、安装cuda及VS2019 https://www.bilibili.com/read/cv7335974/ 2、netcdf.h头文件找不到问题 https://www.cnblogs.com/lyggqm/p/12926974.html https://blog.csdn.net/u011954296/article/details/54617048 3、编码问题 https://blog.csdn.net/qq_33485434/article/details/81196843 4、

我的笔记 4121

获取上传至DMS服务器上文件的URL

如果需要失效时间延长会设置URL永久有效, 可以去修改函数SCMS_URL_GENERATE的参数DURATION 或EXPIRATION ,DURATION最大时间是999999,若需要永久有效,则需要设置EXPIRATION的时间,这时系统会忽略DURATION的参数,生成URL的时候 SCMS_URL_GENERATE会调用SCMS_URL_SIGN函数这是其中默认这是了URL的生效时间为两小时。

一只学习的渣渣 549

ardupilot 方向余弦矩阵/旋转矩阵的理解

本节主要记录自己对ardupilot中用到的方向余弦矩阵/旋转矩阵的理解,欢迎批评指正,有些资料参考网上写的比较好的资料,免得查找资料麻烦。旋转矩阵的坐标理解:表示从旋转矩阵的下标的坐标系的坐标变换到上标表示的坐标系坐标下。旋转矩阵的坐标系理解:表示从旋转矩阵的上标的坐标系变换到下标表示的坐标系下。从旋转矩阵的投影更好理解,比如下面旋转矩阵的第一行是左边坐标系的第一维分量在右边坐标系的投影。

陌城烟雨 612

虚拟网络的“隐形盾”:C#如何用代码把DDoS踢出门?

本文分享了如何用C#防御DDoS攻击的实战经验。通过三种核心防御策略:1)基于IP的速率限制中间件,使用滑动时间窗口算法控制请求流量;2)自动IP封禁服务,通过特征检测识别恶意IP并加入黑名单;3)优化数据库连接池和HTTP客户端连接池,合理配置资源参数。文中提供了详细的C#代码实现,包括限流中间件、IP封禁服务和连接池优化方案,并分享了生产环境中的调优经验,如配合Redis实现分布式限流、使用fail2ban自动封禁等技巧,帮助开发者构建更健壮的防御体系。

墨夶的博客 330

验证 helm Chart 的正确性

验证 helm Chart 的正确性

小橙子的笔记屋 283

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

上一篇: 7、游戏世界滚动编程全解析
下一篇: 9、信息时代下的责任、开放与所有权困境
ruby5
博客等级 码龄15年 29粉丝 893原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址