【风马一族_Java】如何使用ACSLL表的值,

------------------------------------------------------------------------------

一,依次ACSLL表的值

将自然数赋值给char类型的变量,然后输出char类型的变量,其值就是ACSLL表上对应的值

这里只显示ACSLL表中的33~126间的字符

------------------------------------------------------------------------------

 1 public class sows {
 2 
 3     public static void main(String[] args) {
 4 
 5         char ch1 = 48;
 6         char ch2 = 57;
 7         char ch=29;
 8 
 9         int number;
10 
11         for (int i = 0; i < 10; i++) {
12             for (int j = 0; j < 10; j++) {
13                 number=++ch;
14                 System.out.print(number+": "+ch + "\t");
15                 if (number > 125) {
16                     break;
17                 }
18             }
19             System.out.println();
20         }
21         System.out.println("ch1="+ch1 + " " +"ch2="+ch2);
22     }
23 }

运行的结果:

------------------------------------------------------------------------------

2:利用ASCLL表,随机产生字符

------------------------------------------------------------------------------

 1 //*********************************************
 2 //    产生一串长度为10的随机数字
 3 //
 4 //*********************************************
 5 public class random {
 6     public static void main(String args[]){
 7         Random random=new Random();
 8 
 9         for (int i = 0; i < 10; i++) {
10 
11             char chars= (char) (48+random.nextInt(10));
12 
13             System.out.print(chars);
14         }
15     }
16 }

运行结果:

  4865033302

--------------------------------------------------------------------------------------------------------

 1 //*************************************************
 2 //    产生一串长度为10的随机数据
 3 //
 4 //*************************************************
 5 public class random {
 6     public static void main(String args[]){
 7         Random random=new Random();
 8 
 9         for (int i = 0; i < 10; i++) {
10 
11             char chars= (char) (48+random.nextInt(20));
12 
13             System.out.print(chars);
14         }
15     }
16 }

运行结果:
  @4>0?@>01=

总结:使用char类型来产生字符,比之前使用String[]类型方便多,String[]还需要把字符事先写出来,而char本身就能直接使用字符。感觉方便,只是开头反而费时间多。

   要省时间,技术不容易提升,要使用方便的方式编写代码,则开头需要花点时间,从长久来看,是划算的交易。而短时间内,不可取。再接再厉。

  

 

转载于:https://www.cnblogs.com/sows/p/5614427.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值