Java--输入一行字符统计出其中英文字母、空格、数字和其它字符的个数。

(JAVA编程练习):输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 前言: 万物已近极致 如今,世间的一切都已经达到完美,因此,想要造就一位智者,花费的时间可能比在希腊时期造就希腊七贤还要多,而要与一个人进行博弈,所花费的智谋恐怕比对付一个民族还要多。 1、补充 toCharArray() 方法 (1)作用: 将字符串转化为字符数组。 (2)语法: public char[] toCharAr... 阅读详情
import java.util.Scanner;

public class test {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("输入字符:");
		String c= scanner.nextLine();
		char[] str=c.toCharArray();
		int abc,blank,num,other;
		abc=blank=num=other=0;

		for (int i = 0; i < str.length; i++){
			if(str[i]>='A'&&str[i]<='z')
				abc++;
			else if(str[i]>='0'&&str[i]<='9')
				num++;
			else if(str[i]==' ')
				blank++;
			else
				other++;
		}
		
		System.out.println("这段字符串中英文字母:"+abc+"个,空格:"+blank+"个,数字:"+num+"个,其他字符:"+other+"个。");

	}

}

示例输出
在这里插入图片描述

StChar.java 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 //【程序7】 StChar.java 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 //1.程序分析:利用while语句,条件为输入的字符不为'\n'. import java.io.*; import javax.swing.JOptionPane; public class StCharApp { /** * @param args */ pub 阅读详情

相关推荐

输入一行字符,用Java分别统计出其中英文字母、空格、数字和其他字符的个数。

输入一行字符,用Java分别统计出其中英文字母、空格、数字和其他字符的个数。 package p3; import java.util.*; public class floatlength { public static void main(String[] args) { int digital=0; int character=0; int other=0; int...

慕云 1848

java 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

这里需要导入Scanner,值得注意的是:我们在使用字符串的时候需要使用next();其他的类型例如int 使用的是intnext(),但是你会发现并没有stringnext(),我们这里直接使用next()即可。我们这为什么会重新将字符串赋值给char e呢,因为我们要使用到Ascall码,所有先将字符串转换为字符,使用charAt这一方法。

2301_80471482的博客 1165

AI数字人短视频数字人口播数字人分身建模流程全解析

在人工智能与计算机图形学蓬勃发展的当下,数字人建模作为打造虚拟数字人的核心环节,其流程复杂且精妙,融合了多种前沿技术与创意构思,为栩栩如生的数字人形象奠定基石。​。

2403_87518095的博客 1454

java实现输入一行字符,分别统计其中的英文字母,空格,数字,和其他字符的个数

主要原理: 定义四个变量用来积累个数 利用Scanner录入字符串 使用.toCharArray转换字符串 for循环遍历字符 if判断每个字符类型 打印各个类型字符个数 import java.util.Scanner; public class experiment0205 { public static void main(String[] args) { int a = 0 ; int b = 0 ; int c = 0 ; int d = 0 ; Scanner sc

m0_68203364的博客 1万+

Mask2Former实战:用SwinTransformer+Deformable Attention搞定图像分割三大任务

本文实战解析了Mask2Former模型如何统一解决语义、实例和全景分割三大任务。通过集成Swin Transformer骨干网络与创新的Deformable Attention及Masked Attention机制,详细介绍了模型构建、训练策略及在COCO数据集上的性能表现,为开发者提供了高效的图像分割解决方案。

tech5的博客 248

RDD2022 数据格式转换与清洗

Rdd2022数据集,是关于道路损伤的数据集,与rdd2020相比增加了两万多张图片但是由于格式不能被yolo直接使用且其中有大量的图片没有符合要求的标注,特写此文章记录数据清洗与格式化的过程。

蓝胖子的博客 9982

java:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

程序分析:利用while语句,条件为输入的字符不为’\n’.代码如下:第一种: import java.util.Scanner; public class Prog7_1{ public static void main(String[] args){ System.out.print("请输入一串字符:"); Scanner scan = new Scan

哦,也好的博客 2万+

Mac上MySQL出现secure-file-priv为null

在使用MySQL导入导出文件时出现了错误,原因是没有配置secure-file-priv。 我的MySQL版本是8.0.13,使用如下命令查看secure-file-priv。 结果发现secure-file-priv为空,此时需要为它配置一个文件夹。 解决方案: 1)到MySQL的安装目录中去,Mac中是的是 /usr/local/mysql/support-files,该目录下有一...

zhangvalue的博客 5887

Java练习:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符 的个数。

程序分析:利用while语句,条件为输入的字符不为’\n’. 方法一: import java.util.Scanner; public class Test { public static void main(String[] args) { System.out.println("请输入一段字符串……"); Scanner input = new Scanner(System.in); String a = input.nextLine();

m0_46695871的博客 4507

MATLAB R2022b 安装教程

1. 下载安装先放资源链接,百度网盘太贵了不想续了,换了夸克网盘。1. 下载安装。

qq_51654158的博客 2万+

ESP32 WIFI 智能巡线小车设计与实现(四足 / 四轮通用)

本文设计的 ESP32 WIFI 智能巡线小车,硬件模块化、软件轻量化,兼容四足与四轮两种结构,实现了自动巡线与 WIFI 远程控制双功能。系统成本低、易上手,适合嵌入式初学者学习 WIFI 通信、传感器应用、运动控制等核心知识点,也可在此基础上扩展蓝牙控制、避障、视觉识别等功能。

weixin_42300449的博客 155

用java实现输入一行字符,分别统计出其中中文汉字、英文字母、空格、数字和其它字符的个数

本文讲述的是如何用java去实现输入一行字符,分别统计出其中中文汉字、英文字母、空格、数字和其它字符的个数这样的功能

SSS4362的博客 7920

【PostgreSQL数据分析实战:从数据清洗到可视化全流程】5.2 数据分组与透视(CUBE/ROLLUP/GROUPING SETS)

【PostgreSQL数据分析实战:从数据清洗到可视化全流程】5.2 数据分组与透视(CUBE/ROLLUP/GROUPING SETS)

kngines 1842

JAVA实现输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

package com.test; import java.util.Scanner; public class Main { //输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数 public static void main(String[] args) { Scanner in = new Scanner(System.in); ...

Julyanna_Baker的博客 1万+

OTG原理讲解

摘要:USB OTG(On-The-Go)是USB 2.0的重要功能,允许设备在主机和从机间动态切换,实现设备间的直接通信。其核心机制是通过ID引脚电平判断角色:Micro-USB中接地为Host,悬空为Device;USB-C则通过CC引脚协商。电路设计需处理ID引脚连接和VBUS电源控制,MCU根据ID状态配置USB控制器模式。典型应用包括手机连接U盘、键盘等外设,极大扩展了移动设备的连接能力。

m0_49476241的博客 3252

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数(java)

输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数 import java.util.Scanner; public class No31 { public static void main(String[] args) { // TODO Auto-generated method stub //输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。 Sca...

魍魉 9095

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

Java_输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

package cn.myAlgorithm; import java.util.Scanner; //输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数 class LetterSpaceDigit { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); ...

Chill Lyn 7422

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

【Java】输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。

输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.nextLine(); char[] c...

LLLLLLFY的博客 2459

【详解】Java输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

接下来,定义一个主类​​,并在其中定义主方法​​main​​,这是Java程序的入口点。// 代码将在这里添加。

牛肉胡辣汤 1243

Java 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

题目: 【问题描述】 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。并打印出来。 【输入形式】 Please input a sentence: 【输出形式】 The number of numbers is: The number of English letters is: The number of blank space is: The number of other characters is: 【输入样例】 This is my 1st JAVA code! 【输出样例】 T

SummerSoul的博客 4377

java-输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

【例题】 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数 for(int i=0;i<str.length();i++) { char c =str.charAt(i); ??? } -> ‘0’ - ‘9’ -> ‘a’ -‘z’ ‘A’ -‘Z’ -> ’ ’ 思路 键盘接收字符串型 因为Scanner 没有char 类型 所以 用String 类型 next() 但是 next() 对输入有效字符之前遇到的空白,next() 方法会自动将

weixin_44591656的博客 4730

JAVA版本:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 题目分析:统计某一种类型的数量的时候,只要将特定的类型重字符中取出,用原来的长度-剩下的长度=某个特定类型的数量。 而正则表达式能很快的取出其中的指定类型。 public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入需要分类的字符串:"); //获

枫 5699

Java基础算法题(07):输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

查看所有50道基础算法题请看: Java的50道基础算法题 package Demo07Character_Count; import java.util.Scanner; public class Caracter_Count { /** * 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 */ /* 分析:这道题没有说要统计每个字...

凉拌糖醋鱼 2610

Java 输入一行字符,请分别统计出英文字母、数字、空格和其他字符个数

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str=sc.nextLine(); char x[]=str.toCharArray();//toCharArray方法,把输入的字符串转换为字符数组 int a=0

inooll的博客 7224

输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数(java)

System.out.println("字符串中含有其他字符数目为:"+OtherCount);System.out.println("字符串中含有英文字符数为:"+zmCount);System.out.println("字符串中含有数字数目为:"+szCount);System.out.println("字符串中含有空格数目为:"+kgCount);System.out.println("总字符数为:"+ch);System.out.print("请输入一行字符:");//定义其他字符的个数。

wlushsnow的博客 1302

输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数【java】

题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

p715306030的博客 1728
上一篇: java--输入某年某月某日,判断这一天是这一年的第几天?
下一篇: Java--求一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...的前20项之和
~祝今在
博客等级 码龄7年 597粉丝 54原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

~祝今在

喝个茶水

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

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

打赏作者

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

抵扣说明:

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

余额充值
⌂ 换网址