三九宝宝网宝宝教育教学论文

使用java语言编写程序统计从控制台输入的一行字符串中数字个数

03月18日 编辑 39baobao.com

[汇编语言中如何用循环结构编写统计负数个数的程序]负数就是大于7f的数 先定义数据段,把数据写在段内 比如用00 00来表示数据结束 data segment db 10,20,30,40,50,60,70,80,1f,12,22,00,00 data ends result segment result e...+阅读

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc=new Scanner(System.in);

String intpatten="[0-9]";

String charpatten="[a-zA-Z]";

String signalpatten="\\W";

int intflag=0;

int charflag=0;

int signalflag=0;

String str=sc.next();

String[] strs = new String[str.length()];

for(int i=0;i

strs[i]=str.substring(i,i+1);

if(strs[i].matches(intpatten))

intflag++;

else if(strs[i].matches(charpatten))

charflag++;

else

signalflag++;

}

System.out.println("字符个数:"+charflag+" 数字个数"+intflag+" 非字符数:"+signalflag);

}

正则表达式做 看不懂追问

怎样用java写这个程序:定义一个函数用于统计输入字符串中数字字

public class StringUtils001 { public static void main(String[] args) { String input = getInputString(); int numCount = countNum(input); JOptionPane.showMessageDialog(null, "字符串 [" + input + "] 中数字的个数为:" + numCount ); } /** 计算字符串中数字的个数 */ public static int countNum(String str){ int count = 0; for(char c:str.toCharArray()){ if(Character.isDigit(c)){ count++; } } return count; } private static String getInputString() { String input = null; while(true){ input = JOptionPane.showInputDialog("请输入字符串"); if(input == null || input.trim().length() == 0) JOptionPane.showMessageDialog(null, "忽悠我是吧, 别正个空的字符串啊 ~"); else return input; } } }

请编写一个函数funchar s统计字符串s中的所有数字字符个数并

#include

#define MAX_LEN 25 /* 字符串字符个数 */

int Count(char s[]); /* 计算函数声明 */

main()

{

int i;

int count = 0;

char ch;

char str[MAX_LEN+1]; /* 字符数组 */

str[MAX_LEN] = '\0'; /* 字符串结束标识符 */

clrscr(); /* tuirbo c 2.0 清屏函数 */

printf("input a string : ");

for (i=0;i

ch = getchar();

if (ch=='\n') break;

str[i] = ch;

}

str[i] = '\0'; /* 当前字符串结束标识符 */

count = Count(str); /* 调用计数函数 */

printf("count:%d",count); /* 打印结果 */

}

int Count(char s[])

{

int i;

int c = 0;

for (i=0;s[i]!='\0';i++) {

if(s[i]>='0'&s[i]<='9') c++; /* 判断并计数 */

}

return c;

}

/* 晚安 See you tomorrow !*/

以下为关联文档:

在C语言中要求输入4个数把4个数按从小到大排列起来请问原程序#include <stdio.h> int main() { int a[100],n,i,j,temp; printf("Input the numbers of data:"); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) for(...

C语言问题从键盘输入一个字符串编写一个函数将此字符串中从第//要能自己做就好了。多好的练习机会。 //不自己做也行,把这个看完了默写几次,然后用自己的思路实现一次 #define OK 1 #define NULL 0 #define ERROR 0 #define MAXSSTRLEN 1...

c语言中怎样统计字符串中包含英文字母的个数#include int count_letter(char *str) { char *p = str; int cnt = 0; //开始计数 while (*p != '\0') { if ((*p >= 'a' & *p = 'A' & *p cnt++; } p++; } //计数完成 pri...

用C语言程序编写输入三个数并输出最大值的程序正确代码: #include<stdio.h> int max(int a,int b,int c); int main() { int a = 0,b = 0,c = 0,x; scanf("%d %d %d",&a,&b,&c); x=max(a,b,c); printf("max=%d\n",x); return...

C语言统计字符个数问题两处错误: 1. 算符优先级: while(c=getchar()!='\n') 改成: while((c=getchar())!='\n') 2.拼写错误: if((c>='A')&(c<='z')||(c>='a')&(c<='z')) 改成: if((c>='A')&(c<='Z'...

用c语言中递归调用的方法编写实现:输入的一行字符逆序输出#include <stdio.h> void reverse(char *s) { if (*s) { reverse(s+1); putchar(*s); } } void main() { char a[256]; gets(a); reverse(a); printf("\n"); }...

C语言程序题目:输入10个字符串统计第一个字符是a的字符串1 2 3 4 5 6 7 8 9 10 11 12 #include <stdio.h> intmain(intargc,char*argv[]){ chara[10][100],i,k; printf("Input 10 strings...\n"); for(k=i=0;i<10;i++){ scanf("%100s",...

用C语言编写程序:将从键盘输入的数据存储到文件中再将存储的文用C语言编写程序:将从键盘输入的数据存储到文件中再将存储的文,编写一个程序循环提示从键盘输入数值找出这些数值的最大与最小:代码如下: #include<stdio.h> void read() { FILE...

c语言从键盘输入一字符串c语言从键盘输入一字符串,C语言编程:从键盘中输入一个英文字符串:#include <stdio.h> int main() { char str[100]; long long an[100]; int cnt=0,i=0,f=0; printf("Please inp...

推荐阅读
图文推荐