全英文Java代码 java常用单词

编写一个java程序,输出全部大写英文字母

public class Demo03 {

成都创新互联是专业的松江网站建设公司,松江接单;提供做网站、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行松江网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

public static void main(String[] args) {

for(int i=0;i26;i++){

System.out.print((char)('A' + i) + " ");

}

}

}

用JAVA编一个程序输出全部的英文字母

编码思路

首先考虑到,英文字母的ASCII码是按字母顺序连续的整数,所以可以采用起始字母A递增的方式进行打印

英文字母有大小写之分,大小写字母的ASCII码是不连续的,所以需要分别打印

示例代码

public static void main(String[] args) {

char uc = 'A';

char lc = 'a';

//保存全部大写字母

StringBuilder upperCaseLetters = new StringBuilder("UpperCaseLetters:");

//保存全部小写字母

StringBuilder lowerCaseLetters = new StringBuilder("LowerCaseLetters:");

for (int i = 0; i  26; i++) {

upperCaseLetters.append((char) (uc + i));

lowerCaseLetters.append((char) (lc + i));

}

System.out.println(upperCaseLetters);

System.out.println(lowerCaseLetters);

}

注意事项

不建议将上述变量uc硬编码赋值为65。反之,则可以提高程序的可读性,省去了不必要的注释,也体现出了可移植性的思想。

java实现按词头、词尾提取英文文档中的单词的完整代码代码

public class Test {

public static void main(String[] args) {

Test t =new Test();

File file = new File("E:\\桌面\\words.txt");

try {

ListString list= t.getWords(file, true,"h");

for (String string : list) {

System.out.print(string+"   ");

}

} catch (Exception e) {

e.printStackTrace();

}

}

/**

 * java实现按词头、词尾提取英文文档中的单词

 * @param file 原文件

 * @param isHead 按词头true 按词尾false

 * @param fix 关键词

 * @return

 * @throws Exception 

 */

public ListString getWords(File file , boolean isHead,String fix) throws Exception{

//读取文件中的内容到字符串str

FileInputStream fis = new FileInputStream(file);

BufferedInputStream bis = new BufferedInputStream(fis);

int i=0;

String str = "";

while ((i=bis.read())!=-1) {

str+=(char)i;

}

System.out.println(str);

bis.close();

fis.close();

//将str分割为单词数组

String[] words = str.split(" ");

ListString list = new ArrayListString();

if (isHead) {

for (String word : words) {

if (word.startsWith(fix)) {

list.add(word);

}

}

}else {

for (String word : words) {

if (word.endsWith(fix)) {

list.add(word);

}

}

}

return list;

}

}

java练习题求解希望有完整代码

运行代码

具体的代码如下:

import java.util.HashMap;

public class SearchDemo {

public HashMapInteger,Integer countMap(char[] arr){

HashMap countMap = new HashMapInteger, Integer();

for (int i = 0; i arr.length; i++) {

if(!countMap.containsKey(arr[i])){

countMap.put(arr[i],1);

}else{

int value = (int)countMap.get(arr[i]) + 1;

countMap.put(arr[i],value);

}

}

return countMap;

}

public static void main(String[] args) {

char[] arr={'A','1','R','!','e','','A','5','A','g','#','D'};

int count = new SearchDemo().countMap(arr).get('A');

System.out.println("其中'A'字符的个数是:" + count);

}

}

运行结果

网站标题:全英文Java代码 java常用单词
当前URL:https://www.cdcxhl.com/article18/ddeosdp.html

成都网站建设公司_创新互联,为您提供移动网站建设做网站响应式网站云服务器网站收录

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站建设网站维护公司