PPone的Java学习笔记004

java语言程序-数组编程题目.docx Java初学者 立即下载

有一个整数数组,其中存放着序列1,3,5,7,9,11,13,15,17,19。请将该序列倒序存放并输出。

package com.siso.java;

import java.util.Arrays;

public class Shuzu_daoxu {
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int [] shu={1,3,5,7,9,11,13,15,17,19};
		for(int min =0,max=shu.length-1;min<max;min++,max--){
			int temp=shu[min]; 
			shu[min]=shu[max];
			shu[max]=temp;
			System.out.println(Arrays.toString(shu));

	}
	}
}

实现二维数组整体转置。

package com.siso.java;


public class Shuzu_zhihuan {

		public static void main(String[] args) {
			// TODO Auto-generated method stub
			int [][] s1 ={{1,2,3},{4,5,6},{7,8,9}};
			int [][] s2 = new int[s1.length][];
			for (int i = 0;i < s1.length;i++) {
				s2[i] = new int [s1.length];
			}
			for (int i = 0;i < s1.length;i++){
			for (int j = 0;j < s1.length;j++){
				s2[j][i] = s1[i][j];
			}
		  }
			System.out.println("转置后为:");
			for(int a = 0; a < s2.length;a++){
				for(int b = 0; b < s2.length;b++) {
					System.out.print(s2[a][b]);
					System.out.print(" ");
				}
				    System.out.println();
			}
		}
     }

使用二分查找法在数组中查找关键字key。

package com.siso.java;

import java.util.Scanner;

public class Erfenfa_chazhao {
	
	int search (int [] a,int key) {
		int start = 0;
		int end = a.length-1;
		while (start <= end) {
		int middle = (start+end)/2;
		if (key < a[middle]) {
			end = middle - 1;
		} else if (key > middle) {
			start = middle + 1;
		} else {
			return middle;
		  }
		}
		return -1;
		}	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int [] a = {11,32,425,656,7575,6564};
		System.out.println("请输入你想要查询的key值:");
		int b = in.nextInt();
		/*若直接写System.out.println(search(a,));,会出现报错说静态不能引用非静态
		因为通过Scanner获取的b值是非静态的值,所以报错,解决方法为新建一个ao类,
		然后int c,将ao的值赋值给c,再输出c的值。*/
		Erfenfa_chazhao ao = new Erfenfa_chazhao();
		int c =ao.search(a, b);
		System.out.println("若找到key值则返回key值,否则返回-1");
		System.out.println("结果是:"+c);		
	}
}
练习--控制台购物管理系统 java控制台程序实现的购物管理系统,数据只保留在内存中。有登录界面,用户密码可修改,会员信息可以增查改。 立即下载

相关推荐

【AI生成PPT】使用ChatGPT+Overleaf自动生成学术论文PPT演示文稿

本文介绍了一种利用ChatGPT、Beamer和LaTeX自动生成学术论文PPT演示文稿的高效方法。通过Beamer的演示文稿文档类和Overleaf的云端LaTeX协作平台,用户可以在10分钟内完成专业排版。核心流程包括从arXiv获取论文源码,使用ChatGPT生成Beamer代码,并在Overleaf上编译生成PDF格式的PPT。生成的PPT包含标题页、研究背景、方法、实验等完整章节,排版简洁专业。该方法显著提升了效率,完美支持公式、算法和参考文献引用,适用于学生和研究人员快速制作学术汇报或会议演示文

我们都是被分成两半的人,一边热爱生活,一边憎恨生活。面对生活,我们总是在矛盾的两端摇摆,在反复的矛盾和犹豫中,一边踉跄前行,一边重振旗鼓。我渴望改变,渴望变得更好,渴望找到出口……就像一个溺水人的挣扎,就像一个救生圈。我是一个矛盾集合体,想要变得快乐,但是 4659

有一个整数数组,其中存放着序列1,3,5,7,9,11,13,15,17,19。请将该序列倒序存放并输出。

#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int a[10]=...

weixin_45721847的博客 7434

crowdcountingp2p代码复现

前面学习了一下论文:Improved Field-Based Soybean Seed Counting and Localization with Feature Level Considered该论文的模型原型由CrowdCounting-P2PNet改进而来这里先复现一下CrowdCounting-P2PNet模型,然后再学习P2PNet-Soy模型。

m0_73832962的博客 2338

Java------数组使用及排序练习

1.有一个整数数组,其中存放着序列1,3,5,7,9,11,13,15,17,19。请将该序列倒序存放并输出。 2.使用选择排序和冒泡排序对一自定义数组进行排序; 3.先对数组{1,3,9,5,6,7,1,5,4,8}进行排序,然后二分查找法找出数组中的元素8,标出其排序后其下标的位置。 4.编写一个程序,生成0-9之间的100个随机整数并且显示每一个数的个数 1.编写一个Array类...

王雪亮 3942

SAP PP模块 MRP配置实战:5步完成工厂级物料需求计划激活

本文详细介绍了SAP PP模块中物料需求计划(MRP)的工厂级配置实战,通过5个关键步骤从基础环境准备到最终激活。内容涵盖SPRO后台配置、MRP控制者定义、主数据设置及核心参数调整,帮助顾问快速掌握MRP配置清单的完整流程,确保物料需求计划的高效运行。

weixin_30431445的博客 354

微信小程序返回按钮的隐藏玩法:用onShow实现数据自动刷新(附完整代码)

本文深入探讨了微信小程序中用户点击返回按钮后,如何利用onShow生命周期函数实现页面数据的自动刷新。文章对比了onLoad与onShow的差异,提供了从基础的本地存储标记到进阶的EventChannel事件通信,再到状态管理库的多种解决方案,并附有完整的代码示例,帮助开发者构建流畅的用户体验。

agile9scrum的博客 932

java数组排序练习题

大家好,我是今晚打老虎,接下来把我所学习的东西分享给大家! 昨天主要做了关于int类型数组的四道练习题,不知道我写的代码有木有性能上的问题,还请大神指教 题目一:有一个整数数组,其中存放着序列1,3,5,7,9,11,13,15,17,19。请将该序列倒序存放并输出 上代码: int[] a= {1,3,5,7,9,11,13,15,17,19}; for(int i=0;i<a.length;i++) {

胡广的比特星球 3026

MATLAB仿真实战:双有源桥(DAB)变换器的扩展移相调制(EPS)全流程解析

本文提供了一份详细的MATLAB/Simulink仿真实战指南,手把手解析双有源桥(DAB)变换器在扩展移相调制(EPS)下的全流程建模。内容涵盖从核心原理、主功率电路搭建、EPS驱动信号生成,到仿真运行、波形分析及模型优化的完整步骤,旨在帮助工程师和研究者快速掌握DAB变换器的仿真与性能验证方法。

o4p5q6r7s的博客 519

python面试题练习

1、一行代码实现 1--100 之和 In [10]: sum(range(101)) Out[10]: 5050 sum()方法对系列进行求和计算。sum函数的参数必须是可迭代的对象 range() 函数可创建一个整数列表,一般用在 for 循环中。 2、如何在一个函数内部修改全局变量 利用 global 修改全局变量 3、列出 5 个 python 标准库 ...

diaojiao6326的博客 1083

软考高级-系统架构设计师 论文范文参考(一)

系统架构设计师 论文参考

片言可决讼,半纸能缚龙 4361

AUTOSAR从入门到精通-汽车虚拟控制器(vECU)(二)

虚拟控制器的概念其实一直都存在,可能稍微有点差异,与此相关的有主机厂或供应商的ECU系统仿真或或控制策略开发工作。简而言之,虚拟控制器是一种软件工具,用于模拟ECU的功能和性能,无需实际的ECU硬件载体。source: 什么是虚拟ECU?- dSPACE空间虚拟控制器的原理主要是基于软件仿真技术,它可以模拟各种传感器的输入,执行器的输出和控制器的算法逻辑,它也可以模拟与实际控制器之间的通信接口,以便与其他ECU进行交互,如CAN总线通信等。

getusushu的博客 913

JAVA小练习-二分查找法

public class BinarySearch { public static void main(String[] args) { // 需要注意的一点是,在进行Binary Search之前,要保证数组是有序的。 int[] searchArray = {15,32,46,54,56,69,89}; for(int i=0;i<searchArray.lengt

技术世界的五彩缤纷 594

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

PPone的Java学习笔记001

Java学习笔记001 实现输入学生姓名,年龄,成绩输入和输出。 package siso; import java.util.Scanner; public class Student { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in =new Scan...

PPone117的博客 544

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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...

PPone的Java学习笔记002

模拟银行取钱,如果输入的密码为“12345”,登陆成果,提示“可以取钱”,否则提示“密码错误,请重新输入” package siso; import java.util.Scanner; public class Siso2 { public static void main(String[] args) { // TODO Auto-generated method stub S...

PPone117的博客 469

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

PPone的Java学习笔记003

通过调用两个整数交换的方法,是否能实现两个整数的交换? package com.siso.java; import java.util.Scanner; //通过调用两个整数交换的方法,是否能实现两个整数的交换? public class Fangfa { //类的属性 //定义类的方法 void get(int a,int b) { a = a+b; b = a-b; ...

PPone117的博客 400

JAVA练习(5)

有一个整数数组,其中存放着序列1,3,5,7,9,11,13,15,17,19。请将该序列倒序存放并输出。 package wu; public class Dx { public static void main(String[] args) { int [] a={1,3,5,7,9,11,13,15,17,19}; int [] b=new int[a.length]; for(int i=a.length-1;i>=0;i--) { b[i]=a[i];

DuHuangod的博客 1978

Java基础语法十一(多维数组)

多维数组,稀疏数组,以及一些练习题

tiger_root的博客 413

整理的java题目

使用Character提取字符串中的大写字母和小写字母 : public class primary { public static void main(String[] Args) { String sr1="Whatever happen,I am still live with you!"; String sr2=""; String sr3=""; for(int i=0...

qq_45639511的博客 646

初始化 int 类型数组 data 1 []={1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20}

初始化 int 类型数组 data 1 []={1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20} ,先用任意一种算法对其进行排序,然后提示用户输入一个数字,应用本章的折半查找函数模板找出它的位置。 #include<iostream> using namespace std; template<class T> v...

邹氏情歌cium的博客 8278

初始化int类型data1[ ]={1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20}先使用任意一种算法对其排序提示用户输入一个数字,再折半查找

初始化int类型data1[ ]={1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20}先使用任意一种算法对其排序提示用户输入一个数字,应用折半查找函数模板找出它的位置。#include using namespace std; template void mySwap(T&x, T&y) { T temp = x; x = y;...

saosaomilk的博客 2756

C语言 ,有15个数按由大到小顺序存放在一个数组中,输入一个数,要求用拆半查找法找出该数是数组中的第几个元素的值,如果该数不在数组中,则输出“无此数”

注意此题是要求用拆半法#include<stdio.h> int main() { int t[9]={1,3,5,7,9,11,13,15,17}; int start=0,end=8,c,mid; //start表示查找区间开始的位置,end是查找区间的最末位置 scanf("%d",&c); while(start<=end) { mid

luo44671854的专栏 2万+

java多维数组

二维数组实质就是存储是一维数组。数组定义数组类型[][]数组名=new数组类型[一维数组的个数][每一个一维数组中元素的个数];练习题1使用二维数组打印一个10行杨辉三角。

weixin_50518344的博客 392

数组练习题

编写一个程序,提示用户输入学生数量后,再依次输入姓名和成绩,按照成绩的降序来打印学生的姓名。个整数,并且存储其中互不相同的数,最后将这。、有一个整数数组,其中存放着序列。,请将该序列倒序存放并输出。、编写一个程序,能够读入。...

m0_59749255的博客 215

Java EE 进阶:11. SpringBoot 统一功能处理(第二弹):DispatcherServlet 源码分析+适配器模式

Java EE 进阶:11. SpringBoot 统一功能处理(第二弹):DispatcherServlet 源码分析+适配器模式

要努力去发光,而不是被照亮~ 343
上一篇: PPone的Java学习笔记003
下一篇: canvas绘制笑脸
PPone117
博客等级 码龄7年 4粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值