使用ArrayList对大小写字母的随机打印
来源:互联网 发布:网络英语外教一对一 编辑:程序博客网 时间:2024/05/29 18:25
从a~z以及A~Z随机生成一个字母并打印;打印全部的字母
package com.liaojianya.chapter1;import java.util.ArrayList;/** * This program demonstrates the way of generating random a~z, A~Z. * @author LIAO JIANYA * */public class RandomCharacters{public static void main(String[] args){ArrayList<Character> list = new ArrayList<Character>();for(char i = 'a'; i <= 'z'; i++){list.add(i);}for(char i = 'A'; i <= 'Z'; i++){list.add(i);}String str = "";int num = (int)(Math.random() * 52);System.out.print("第" + num + "个字母为:");str = str + list.get(num);System.out.println(str);System.out.println("----------打印出a~z以及A~Z--------------");for(Character s : list){System.out.print(s);}}}
运行结果
第3个字母为:d----------打印出a~z以及A~Z--------------abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
这里使用了ArrayList这个动态数组的方法,通过for循环以及add的方法来添加元素;使用增强型for循环,打印出list中所有的元素。
0 0
- 使用ArrayList对大小写字母的随机打印
- javascript 生成随机大小写的字母
- C++ 随机 大小写字母数字
- java---大小写字母和数字的随机组合的随机数
- 生成随机的验证码?大小写字母和数字
- web前端js中随机生成指定位数的字母数字、组合字符串可选择字母大小写
- 字母的大小写转换
- 转换字母的大小写
- 大小写字母的转换
- 大小写字母的排序
- 字母大小写的问题
- 字母的大小写互换
- 转换字母的大小写
- 大小写字母的转换
- 字母的大小写转换
- 大小写字母的转换
- 大小写字母的转换
- 字母大小写的转化
- The content of the adapter has changed but ListView did not receive a notification的解决方案
- 初步理解android的MediaScanner(1)
- linux--tomcat安装
- 顺序表应用2:多余元素删除之建表算法
- 图标素材网站
- 使用ArrayList对大小写字母的随机打印
- Android开发之蓝牙通信(二)
- Hibernate二级缓存的全局配置
- Hibernate1
- 高速公路(freeway)
- sql 杂文
- android studio 导入eclipse项目,程序真机运行中文显示乱码
- 各种小片段
- 数据结构迷宫问题