C语言既不是大写也不是小写,在java里用最简单的方法编写一个程式,判断输入的是大写字母还是小写字母还是数字,或字串?...

在java里用最简单的方法编写一个程式,判断输入的是大写字母还是小写字母还是数字,或字串?以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

8f4bd64bca058c68ab4318d437c9402c.png

在java里用最简单的方法编写一个程式,判断输入的是大写字母还是小写字母还是数字,或字串?

全部利用String的自身方法来判定

import java.util.Scanner;

public class Validator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

String str = scanner.nextLine().trim();

if(str.length() > 1){

System.out.println("输入的是字串");

}else if(str.matches("[a-z]")){

System.out.println("输入的是小写字母");

}else if(str.matches("[A-Z]")){

System.out.println("输入的是大写字母");

}else if(str.matches("[0-9]")){

System.out.println("输入的是数字");

}else{

System.out.println("输入的既不是字串,也不是大小写字母,也不是数字!");

}

}

}

输入字元判断是数字还是小写字母大写字母C++

if条件判断

数字:字元范围0~9

小写字母:a~z

大写字母:A~Z

VB编写一个程式,统计输入的字串中小写字母、大写字母、数字及其他符号的个数

Private Sub Command1_Click()

s = Len(Text1)

For i = 1 To s

If Mid(Text1, i, 1) <> 32 Then '没空格

If 97 < Asc(Mid(Text1, i, 1)) And Asc(Mid(Text1, i, 1)) < 122 Then a = a + 1 '小写字母

If 65 < Asc(Mid(Text1, i, 1)) And Asc(Mid(Text1, i, 1)) < 90 Then b = b + 1 '大写的

If 48 < Asc(Mid(Text1, i, 1)) And Asc(Mid(Text1, i, 1)) < 57 Then c = c + 1 '数字

End If

Print d

Next i

Print "小写字母" & a & "个"

Print "大写字母" & b & "个"

Print "数字" & c & "个"

Print "其它(包括空格)" & s - a - b - c & "个"

Print s

End Sub

输入任一字元,输出结果是判断输入的是数字还是大写字母还是小写字母,怎么写程式 啊?

不知道你用什么语言 反正思路就是判断输入字元的ascii码 至于哪些ascii代表哪些字元,自己去查对照表

判断输入的字元是大写还是小写字母,用函式完成。如图。 判断输入的字元是大写还是小写字母,用函式完成

#includeint f(char c) { int r=0; if ( c>='a' && c<='z' ) r=1; else if ( c>='A' && c<='Z' ) r=2; return r; }void main() { char s[20],c; int r; printf("请输入字元:"); gets(s); c=s[0]; r=f(c); if ( r==1 ) printf("%c是小写字母。\n",c); else if ( r==2 ) printf("%c是大写字母。\n",c); else printf("%c不是字母。\n",c);}

、编写程式,判断从键盘输入的是控制字元、数字、大写字母、小写字母还是其他字元。

LZ都没有说用什么语言编写,演算法其实很简单,只要程式判断按键的ASCII码的值就可以了,做一个switch-case的判断

C语言怎么用switch 语句判断输入的字元是大写字母小写字母还是数字?

使用switch判断比较麻烦,不建议使用这种方式。char ch; scanf chswitch(ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': printf("%c is a number.\n", ch); break; case 'a': case 'b': .... case 'z': printf("%c is a lower alphabet.\n",ch); break; case 'A': ... case 'Z': printf("%c is a upper alphabet.\n",ch); break; default: printf("%c is other ascII code.\n",ch);}建议使用#include 中的函式

isdigit

islower

isupper

来进行判断。

初学C++,要求编写一个程式,输入大写字母,输出小写字母

其实很容易,你学习C语言的ASCII程式码就行了,可以把字元转换成整数,而刚好大小写字母只是相差32。 main() { char a, b; a=getchar(); if(a>=90)b=a-32; else b=a+32; printf("%c\n",b); system("pause"); }

用shell指令码语言判断从键盘输入的是小写字母,还是大写字母,还是数字,还是其他字元

利用ascii对应表输出即可,在某个范围是大写,某个范围是小写,某个范围是数字,其他都是字元

分页:

1

23

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值