【风马一族_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 + "	");
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