package exercise;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* 编写一个Java应用程序,从键盘读取用户输入两个字符串,
* 并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加。
* 要进行异常处理,对输入的不符合要求的字符串提示给用户,不能使程序崩溃。
* @author lsq
*
*/
public class StringInput {
public static void main(String[] args) {
String s1 = null,s2 = null,ss,si,sf;
int i1,i2;
float f1,f2;
//☆:实现字符串的输入
BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("输入第一个字符串:");
s1 = strin.readLine();
System.out.println("输入第二个字符串:");
s2 = strin.readLine();
} catch (Exception e) {
System.out.println(e.getMessage());
}
i1 = Integer.parseInt(s1);
i2 = Integer.parseInt(s2);
f1 = Float.parseFloat(s1);
f2 = Float.parseFloat(s2);
ss = strAdd(s1,s2);
si = strAdd(i1, i2);
sf = strAdd(f1, f2);
System.out.println("输入的两个字符串相加结果为:"+ss);
System.out.println("输入的两个字符串转换为整数相加结果为:"+si);
System.out.println("输入的两个字符串转换为浮点数相加结果为:"+sf);
}
public static String strAdd(String str1,String str2){
return str1 + str2;
}
public static String strAdd(int int1,int int2){
return String.valueOf(int1 + int2);
}
public static String strAdd(float float1,float float2){
return String.valueOf(float1 + float2);
}
}
相关推荐
java程序设计编程题
编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加。要进行异常处理,对输入的不符合要求的字符串提示给用户,不能使程序崩溃。
java每日基础编程题(七)
15.编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加。要进行异常处理,对输入的不符合要求的字符串提示给用户,不能使程序崩溃。 package com.liubj.chap01; import java.io.BufferedReader; import java.io.InputStreamReader; public...
ESP32基于Arduino环境开发128*160 TFT_LCD屏幕显示照片
ESP32基于Arduino环境开发128*160 TFT_LCD屏幕显示照片
编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加。要进行异常处理,对输入的不符合要求的字符串提示给用户,不能使程序崩溃。
编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加。要进行异常处理,对输入的不符合要求的字符串提示给用户,不能使程序崩溃。...
雷达截面积建模仿真(RCS)
在目标侧,其形状、材料、尺寸(相对于雷达波长)和相对于雷达观察方向的方向等特征都会影响雷达看到的RCS。严格的数学处理超出了讨论的范围,但入射波和目标之间的相互作用可以定性描述。对于给定的散射方向,可以积分求和物体表面电流的振幅相位,当电流同相时,会出现较大的回波幅度。随着目标方向和雷达视角随时间变化,电流振幅和相位会发生变化,形成看似随机的峰值和零点的散射模式,出现“相长”和“相消”干涉。除了雷达到目标的距离外,雷达截面(RCS)是RRE(雷达距离方程)中唯一与目标相关的参数,因此不在雷达设计者的。
告别屏幕闪烁:手把手教你用示波器抓取并分析MIPI DSI信号(以RK平台为例)
本文详细介绍了如何利用示波器抓取并分析MIPI DSI信号,以解决LCD屏幕闪烁、花屏等问题。以RK平台为例,从工具准备、示波器参数配置到信号捕获与波形解读,提供了一套完整的调试方案,帮助硬件工程师快速定位和解决显示接口信号完整性问题。
编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加,并输出结果。要进行异常处理,对输入的不符合要求的字符串提示给用户。
编写一个Java应用程序,从键盘读取用户输入两个字符串,并重载3个函数分别实现这两个字符串的拼接、整数相加和浮点数相加,并输出结果。要进行异常处理,对输入的不符合要求的字符串提示给用户。 package zyy.wxt.demo; import java.util.Scanner; public class overload { public static void main(Stri...
EMC案例:解决千兆网口RTL8211F EMI问题
摘要:本文分析了Amlogic S812平台OEM项目中RTL8211F-CG千兆网卡EMI辐射超标问题。发现百兆测试时25MHz时钟有3dB余量,但千兆125MHz时钟导致超标。问题根源包括:未关闭PHY芯片悬空CLKOUT引脚、TX/RXCLK端RC位置错误、包地不完整及参考地缺失。解决方案涉及软件关闭无用时钟、优化RC布局、加强包地与打孔、调整共模电感位置,并在HDMI 3.3V加磁珠。关键结论指出千兆网125MHz时钟需严格包地打孔,且RC取值需平衡EMI与通信性能。
03_Scala变量和数据类型
scala变量和数据类型
Aveva Marine C# 二次开发入门001
1# 引用 C:\AVEVA\Marine\OH12.1.SP4\Aveva.ApplicationFramework.dll C:\AVEVA\Marine\OH12.1.SP4\Aveva.ApplicationFramework.Presentation.dll 2# 引用命名空间, using Aveva.ApplicationFramework.Presentation;usi...
鲁棒控制理论 --- H∞ 控制(被裁篇)
鲁棒控制理论 --- H∞ 控制
C++大一基础知识
大一C++基础知识汇总~
18-XLINX的XC7A100T的BANK0引脚说明
DXP_0和 DXN_0是纯输入引脚,Xilinx Artix-7 FPGA 内部集成的一个片上监控模数转换器 的差分模拟输入对,模数转换器的模拟信号输入端,将外部的模拟电压 采样并转换为内部的数字值,是一个单向的信号采集过程。它是与 VCCADC配对的关键引脚,共同为内部的精密模数转换器提供一个纯净、安静、独立的参考地平面。多FPGA同步配置: 在多FPGA系统中,主FPGA配置完成后,可以拉低从FPGA的 INIT_B使其等待,等所有FPGA都准备好后,再同时释放,实现同步启动。
仓颉语言 -- 基础 I/O 操作
仓颉语言 -- 基础 I/O 操作
优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信
优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信今天开始会陆续介绍一些优秀的开源项目,项目基本都是和FPGA或HDL相关的。对于一些找工作或者急需项目经验的人来说,这些项目...
廖雪峰Python教程[完整版]
廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白
C++初学(15)
循环和文本输入的学习
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
JAVA DAY03
JAVA DAY03 局部变量与成员变量 1.在类中的位置不同 成员变量 类中,方法外 局部变量 方法中或者方法声明上(形式参数) 2.作用范围不一样 成员变量 类中 局部变量 方法中 3.初始化值不同 成员变量 有默认值 局部变量 没有默认值 必须先定义 赋值 最后使用 4,在内存中的位置 成员变量 在堆中 局部变量 在栈中 5.生命周期不同 成员变量 随着对象的创建而存在,随着对象的消失而消失 局部变量 随着方法的调用而存在 随着方的调用完毕而消失 封装 将属性隐藏起来,若要访问某个属性 提供公共方法对
STM32F407中文手册
STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。
visio安装包
Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。
3.03.30ajax
ajax
在C语言基础上的C++第一章(基础的输入输出和动态内存开辟)
在 C++ 中,
从一个小程序说起2 - C++快速入门03
从一个小程序说起2 让编程改变世界 Change the world by program 课后题详解(C&C++) 要求:编写一个程序,要求用户输入一串整数和任意数目的空格,这些整数必须位于同一行中,但允许出现在该行中的任何位置。当用户按下键盘上的“Enter”键时,数据输入结束。程序自动对所有的整数进行求和并打印出结果。 C语言版本:homework.c(...
C++语言基础
标准c++
1.c++入门基础【由浅入深-C++】
本文介绍c++入门的相关内容。
2021-03-16
数据类型 一、基本数据类型 1、整数型:byte (1字节) short(2字节) int(4字节) long(8字节) 拜特儿 学儿特 2、浮点型:float(4字节) double(8字节) 浮漏特 代波 3、字符型:char(2字节) 4、布尔型:boolean(1字节) 二、引用数据类型 类 、数组 、接口 、字符串 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TYvyJu1c-16
C++编程
c++
742



被折叠的 条评论
为什么被折叠?



