最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何在java中获取字母的数字位置?

SEO心得admin37浏览0评论
本文介绍了如何在java中获取字母的数字位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在java中获取字母的数字位置?

How to get numeric position of alphabets in java ?

假设通过命令提示我输入了abc然后作为输出我需要得到123我怎么能得到java中字母的数字位置?

Suppose through command prompt i have entered abc then as a output i need to get 123 how can i get the numeric position of alphabets in java?

提前致谢。

推荐答案

String str = "abcdef"; char[] ch = str.toCharArray(); for(char c : ch) { int temp = (int)c; int temp_integer = 96; //for lower case if(temp<=122 & temp>=97) System.out.print(temp-temp_integer); }

输出:

123456

123456

@Shiki for Capital / UpperCase字母使用以下代码:

@Shiki for Capital/UpperCase letters use the following code:

String str = "DEFGHI"; char[] ch = str.toCharArray(); for(char c : ch) { int temp = (int)c; int temp_integer = 64; //for upper case if(temp<=90 & temp>=65) System.out.print(temp-temp_integer); }

输出: 456789

发布评论

评论列表(0)

  1. 暂无评论