黑马程序员——求一个字符串在另一个字符串中的出现次数

黑马程序员-黑马程序员训练营基础测试 为了帮助更多的人了解黑马,同时也 阅读详情

               ----------------------     android培训      java培训   期待与您交流!    ----------------------   
                        

//查找一个字符串在另一个字符串中的出现次数
	public static void count(String str,String key){
		int count=0;
		int index=0;
		while((index=str.indexOf(key))!=-1){
			str=str.substring(index+key.length());
			System.out.println(str);//截取后的字符串
			count++;
		}
		System.out.println("出现的次数:"+count);
	}
	//查找一个字符串在另一个字符串中的出现次数
	public static void count_1(String str,String key){
		int count=0;
		int index=0;
		while((index=str.indexOf(key,index))!=-1){
			index=index+key.length();
			count++;
		}
		System.out.println("出现的次数:"+count);
	}
               ----------------------     android培训      java培训   期待与您交流!    ----------------------   
                         详细请查看       http://edu.youkuaiyun.com/heima


黑马程序员考试题 题目一 文本文件中存储了多个文章标题、作者,标题和作者之间用若干空格(数量不定)隔开,每行一个,标题有的长有的短,输出到控制台的时候最多标题长度10,如果超过10,则截取长度8的子串并且最后添加“...”,加一个竖线后输出作者的名字。 namespace test1 { class Program { /*文本文件中存储了多个文章标题、作者,标题和作者之间 阅读详情

相关推荐

黑马程序员_基础测试

-------android培训、java培训、期待与您交流! ----------

扬帆远航 2260

获取一个字符串在另一个字符串中出现的次数。 比如:获取“ ab”在 “abkkcadkab” 中出现的次数

对题目为”获取一个字符串在另一个字符串中出现的次数。 比如:获取“ ab”在 “abkkcadkab” 中出现的次数“进行了两种方法的讲解以及对第二种方法进行了改进

小贺想改变 1997

SAP CO-PA获利分析避坑指南:从数据采集到报表设计的5个关键步骤

本文深入解析了SAP CO-PA获利分析模块从数据采集到报表设计的完整流程。文章重点剖析了数据源头、特征派生、获利段设计等关键步骤,并对比了基于账户与基于成本核算两种模式的差异,特别强调了在S/4HANA时代的选择与常见陷阱,旨在帮助企业构建可靠、可执行的盈利分析体系。

flink9streamer的博客 826

String练习二、获取一个字符串在另一个字符串中出现的次数。

获取一个字符串在另一个字符串中出现的次数。比如:获取“ab”在 “abkkcadkabkebfkaabkskab” 中出现的次数 public int getCount(String mainStr,String subStr){ int mainLength = mainStr.length(); int subLength = subStr.length(); int count = 0; int index = 0;

qq_37711173的博客 435

CloudCompare点云滤波实战:三种植被去除技术的对比与应用

本文详细对比了CloudCompare中三种植被去除技术(低通滤波、CSF滤波和坡度法)的实战应用与效果。通过具体案例和参数优化建议,帮助用户根据地形特征选择最佳滤波方法,提升点云数据处理精度和效率,特别适用于复杂场景下的植被去除需求。

weixin_30689307的博客 84

CentOS 7下rsyslog日志服务器搭建全攻略:从安装到避坑

本文详细介绍了在CentOS 7系统上搭建rsyslog日志服务器的完整流程,从基础安装到高级配置,包括协议设置、日志模板设计、安全加固和性能优化。特别分享了生产环境中的实战技巧和常见问题解决方案,帮助用户高效构建可靠的日志管理系统。

happy2的博客 687

Python—求一个字符串中每个字符出现的次数

def count(a): a = a # 定义一个空字典 b = {} # 求出字符串长度 c = len(a) i = 0 while i < c: # 当定义的字典里有这个字符把他的值加一 if a[i] in b: b[a[i]] += 1 # 当定义的字典...

weixin_41667438的博客 8088

树莓派与ROS2

树莓派与ROS2(Robot Operating System 2)的结合使用为机器人开发、自动化控制以及物联网项目提供了强大的平台。

weixin_47695827的博客 1754

java-记录一个子串在整串中出现的次数

任务描述: 编写一个程序,记录一个子串在整串中出现的次数,例如记录子串“nba”在整串“nbaernbatnbaynbauinbaopnba”中出现的次数,通过观察可知子串“nba”出现的次数为6.要求使用String类的常用方法来计算出现的次数。 任务目标: 学会分析“记录一个子串在整串中出现的次数”任务的实现思路 根据思路独立完成“记录一个子串在整串中出现的次数”任务的源代码编写、编译及

Best_xing的博客 1万+

goahead(嵌入式Web服务器)之文件传输篇

goahead文件上传原理: 使用html form即表单提交文件上传请求,web服务器核心处理接收客户端Post过来的文件数据(注意post的是二进制数据),最后,web服务器把接收到文件数据以二进制格式写到服务器本端存储系统。 goahead文件上传步骤: 1、创建upload.html文件,内容如下: <html> <head> <meta charset="utf-8"/> <title>Upload</title> </head&g

weixin_40732273的博客 3495

YOLOv11全网首发:注意力独家魔改 | 具有切片操作的SimAM注意力,魔改SimAM助力小目标检测

1)直接作为注意力使用,效果秒杀SimAM;2)高效和卷积结合,代替原始网络的卷积操作;

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1571

黑马程序员最新Python教程——第一阶段(1)

黑马程序员最新Python教程,8天python从入门到精通,学python看这套就够了(笔记)

这里有一只小马吖 1万+

手把手教你使用 YOLOv11/v8 算法 + PaddleOCR 算法完成车牌检测和车牌识别系统,AI智能体,毛玻璃系统,包括PaddlePaddle安装、数据集预处理、模型训练、AI大模型应用等

手把手教你使用 YOLOv11/v8算法 + PaddleOCR算法完成车牌检测和车牌识别系统,AI智能体,毛玻璃系统,包括PaddlePaddle安装、数据集预处理、模型训练、AI大模型应用等。车牌识别系统支持 蓝牌、绿牌、黄牌、双层车牌等车牌识别。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 2780

黑马程序员-计算字符串中每种字符出现的次数

---------------------- ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ---------------------- 题目:计算字符串中每种字符出现的次数。“Welcome to Chinaworld”,不区分大小写,打印“W 2”“e 2”“l 3”…… 解题思路: 1、将字符串统一转为大写或者小写(string.uppe

First Step:Hello World 1348

CATIA 3DEXPERIENCE R2019x VBA开发介绍

CATIA 3DEXPERIENCE R2019x VBA开发介绍 一、 什么是VBA? 【VBA的官方解释】 VBA(Visual Basic for Applications)是VisualBasic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。主要能用来扩展Windows的应用程序功能,特别是MicrosoftOffice软件。它也可说是一种应用程式视觉化的 Basic 脚本。 CATIA提供了多种二次开发的接口,其中包括自动化对象编程(Automation)和

WorkMan的博客 5062

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

黑马程序员——统计文件中每个英文单词出现的次数

------- android培训、java培训、期待与您交流! ---------- 需求:有一个文本文件,该文件中存储的有英文单词和中文字符,现在编写一个程序,统计文件中每个英文出现的次数,结果保存到文本文件中。保存的格式为:单词=出现次数,例如there=21,are=6。 分析: 1.数据源:读取的有英文单词的文本文件,是磁盘上的文件,所以数据源是硬盘上的纯文本文件,为了提

LanceDream的专栏 3917

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

黑马程序员--统计小字符串在大字符串中出现的次数

需求:      统计大串中小串出现的次数 举例:   在字符串"woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun" 结果: java出现了5次 分析:   前提:是已经知道了大串和小串。     A:定义一个统计变量,初始化值是0   B:先在大串中查找一次小串第一次出现的位置 a

jingbocl的博客 1212

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

“黑马程序员”基础测试

距我报名开始自学黑马,已经有一个月了。 期间还要工作

ZHOU_XIAO_BING的专栏 1005

黑马程序员总结文档汇总

这篇日志,是这些日子以来观看传智播客视频写的一篇汇总文档,蓝色标识的超链接是doc类型的文档,绿色标识的超链接是思维导图类型的文档,同时两种类型的文档中每篇都提供了文档下载链接,详细内容如下:   黑马程序员 01 Java基础教学 - 01 - 认识Java                                黑马程序员 02 Java基础教学 - 02 - 走进Java

kongbeily的专栏 2143

黑马程序员C++学习总结【核心篇】

附:参考自哔哩哔哩黑马程序员所做的学习笔记

小幸运召唤师的博客 2269

黑马程序员 【】java学习之路——计算字符串中字母出现的次数

-------android培训、java培训、期待与您交流! ----------

黑马程序员【】——java学习之路 829

黑马程序员——字符串

Ctrl+alt+t选中代码然后idea会提示用什么去包围 Ctrl+alt+v自动生成左边 ctrl+d自动复制上一行的代码 字符串的遍历在写代码的时候不可以str.fori生成 要用str.length().fori进行生成 ////****fori是正遍历 反转遍历要用forr 选中遍历用快捷键shift+f6是快捷修改 首先看到方法两个字就要考虑三个问题 第一:我要干嘛?———*** 第二:我干这件事需要什么才能完成?——*** 第三:我干完了是否要把结果返回?——*** 循

m0_73476251的博客 1296

黑马程序员_判断字符串中子串出现的次数

题目如下:           判断一个字符串sdnba1231nbasdfsnbasdfnbasdfsnba中包含子串nba的个数  当看到的这个题目 想到的我的是用String的切割功能spilt           直接把字符串按照子串切割成多少个字符串数组 然后根据再判断数组的情况 比如用 startwith判断是否子串是以子串为起始 和endwith 盘算是否是以子串为结束 在

u013080982的专栏 668

黑马程序员—基础—设计一个方法,用于获取一个字符串中指定子串出现的次数,

package com.heima.gaoshuai; public class Test {         public static void main(String[] args) {                 containsStrNum("hanbasdnbafllgnbahjnbakqqqqlnbaxi","nba");         }

qq_25418233的博客 817

《黑马程序员python教程,8天python从入门到精通,学python看这套就够了》学习笔记总目录

本文是对《黑马程序员python教程,8天python从入门到精通,学python看这套就够了》所有知识点的笔记进行总结分类。 学习时总结的目录笔记以及思维导图和实训,将在后续更新。

放下华子我只抽RuiKe5的博客 8814
上一篇: 黑马程序员——实现字符串反转
下一篇: 黑马程序员——求两个字符串的最大相同字串
King·Forward
博客等级 码龄14年 117粉丝 218原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

King·Forward

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值