「java取出所有大写字母」java第一个字母大写
今天给各位分享java取出所有大写字母的知识,其中也会对java第一个字母大写进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、Java从键盘任意输入一字符串,输出其中的大写字母
- 2、Java题把一个集合的全部字母转成大写
- 3、java中怎么输出字母表中所有的大写字母
- 4、使用JAVA,设定一个含有大小写字母的字符串,先将所以大写字母输出,再将所有小写字母输出!
- 5、java获得汉字的大写字母,其他字符不变
- 6、编写一个java程序,输出全部大写英文字母
Java从键盘任意输入一字符串,输出其中的大写字母
import java.util.Scanner;
public class Demo2 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入任意字符串");
String str = s.nextLine();
System.out.println("原字符串为:"+str);
System.out.println("其中的大写字母为:");
for (int i = 0; i str.length(); i++) {
String ch = str.charAt(i)+"";
if (ch.matches("[A-Z]")) {
System.out.println(str.charAt(i));
}
}
}
}
Java题把一个集合的全部字母转成大写
第一种,把字母拿出来转成int类型 然后加上大小写的差值 再转成字符存进去
第二种,就是直接调用 字符串的方法 toUpperCase
java中怎么输出字母表中所有的大写字母
如下代码可打印大写字母表
public class English {
public void printEnglish()
{
int firstEnglish, lastEnglish;
char firstE = 'A', lastE = 'Z'; //获取首字母与末字母的值
firstEnglish = (int)firstE;
lastEnglish = (int)lastE;
System.out.println("英文大写字母表: ");
for(int i = firstEnglish; i = lastEnglish; ++i)
{
char uppercase, lowercase;
uppercase = (char)i;
lowercase = (char)(i + 32);
System.out.print(" " + uppercase + lowercase);
}
System.out.println();
}
}
使用JAVA,设定一个含有大小写字母的字符串,先将所以大写字母输出,再将所有小写字母输出!
public static void main(String[] args){
String var = "ABsAddHazZ";
char[] str = var.toCharArray();
String upper = "";
String lower = "";
for(int i=0;istr.length;i++){
if(str[i]64str[i]94){
upper += str[i];
continue;
}
if(str[i]96str[i]123){
lower += str[i];
}
}
System.out.println("大写字母是: "+upper);
System.out.println("小写字母是: "+lower);
}
java获得汉字的大写字母,其他字符不变
看看是不是你要的效果!
/**
* 根据汉字提取该汉字的首字母
* @author Administrator
*
*/
public class StringUtil {
// 国标码和区位码转换常量
static final int GB_SP_DIFF = 160;
// 存放国标一级汉字不同读音的起始区位码
static final int[] secPosValueList = { 1601, 1637, 1833, 2078, 2274, 2302,
2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858, 4027,
4086, 4390, 4558, 4684, 4925, 5249, 5600 };
// 存放国标一级汉字不同读音的起始区位码对应读音
static final char[] firstLetter = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'W', 'X',
'Y', 'Z' };
// 获取一个字符串的拼音码
public static String getFirstLetter(String oriStr) {
String str = oriStr.toLowerCase();
StringBuffer buffer = new StringBuffer();
char ch;
char[] temp;
for (int i = 0; i str.length(); i++) { // 依次处理str中每个字符
ch = str.charAt(i);
temp = new char[] {ch};
byte[] uniCode = new String(temp).getBytes();
if (uniCode[0] 128 uniCode[0] 0) { // 非汉字
buffer.append(temp);
} else {
buffer.append(convert(uniCode));
}
}
return buffer.toString();
}
/**
* 获取一个汉字的拼音首字母。 GB码两个字节分别减去160,转换成10进制码组合就可以得到区位码
* 例如汉字“你”的GB码是0xC4/0xE3,分别减去0xA0(160)就是0x24/0x43
* 0x24转成10进制就是36,0x43是67,那么它的区位码就是3667,在对照表中读音为‘n’
*/
static char convert(byte[] bytes) {
char result = '-';
int secPosValue = 0;
int i;
for (i = 0; i bytes.length; i++) {
bytes[i] -= GB_SP_DIFF;
}
secPosValue = bytes[0] * 100 + bytes[1];
for (i = 0; i 23; i++) {
if (secPosValue = secPosValueList[i]
secPosValue secPosValueList[i + 1]) {
result = firstLetter[i];
break;
}
}
return result;
}
public static void main(String[] args) {
System.out.println(":"+StringUtil.getFirstLetter("哈哈123#$bc成功!!!!"));
}
}
有什么疑问可以百度HI我,加点分哦!
编写一个java程序,输出全部大写英文字母
public class Demo03 {
public static void main(String[] args) {
for(int i=0;i26;i++){
System.out.print((char)('A' + i) + " ");
}
}
}
java取出所有大写字母的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java第一个字母大写、java取出所有大写字母的信息别忘了在本站进行查找喔。
发布于:2022-11-25,除非注明,否则均为
原创文章,转载请注明出处。