2013年9月8日星期日

Seek expert coaching a " system license serial number ," the wrong reasons ...

Master, hello :
I am a student studying software engineering , I wrote a "CS structure of the chat system," Today, I ran into a problem code :
I wanted to write a " generation system function authorization " and " serial number generator ," My brother wrote a class file , as follows:


brother serial number of my classes this calculation is the " first call " random numbers " component units throughout the serial number of the engine : the number of milliseconds grab the local system "System.currentTimeMillis ();" method " calculations.
And , where the construction method is in the " required each time a new serial number for the calculation of " appears under this point in time .
Also, print the results obtained here are:

After many friends help, now , will initially positioned at the error :
line 37 of "code character array to string" in the process , we should use "new String ();" constructor method instead, so I modify the code to become following results :

brother I'll line 37 of "toString (code);" method , modified into "new String (code);", however , has not been properly "Output results, " resulting output is as follows:

result , did not receive " any expected system service authorization code" ...
I hope you can tell me the cause of the error code above , if the experts can help me, " I hope you told the brother in me" wrong reasons ", the ability to modify the methods and modified code , written on the back .
Thank you, master coaching ! !
a perfect running day and night to build toward the dreamer
September 5, 2013 Thursday evening 23:23
------ Solution -------- ------------------------------------
Arrays.toString(code)

----- - Solution --------------------------------------------

package d_port_package;

public class D_port_Calc_The_Customer_useAuthorizationCode {
static int[] a = new int[50];
static char[] code = new char[9];
int random = 0;
static int random0_4 = 0;
static int random1_50 = 0;
static int random1_50jumb5 = 0; 
public D_port_Calc_The_Customer_useAuthorizationCode(){
long time2=System.currentTimeMillis(); 
String dataformat = Long.toString(time2);
String Standarddataformat = dataformat.substring(12,13);
System.out.println(Standarddataformat);
random0_4 = Integer.parseInt(Standarddataformat)/2;
random1_50jumb5 = Integer.parseInt(Standarddataformat+1)*5/2;
random1_50 = Integer.parseInt(Standarddataformat)-random0_4;
a[0] = random1_50;
a[3] = random1_50;
a[6] = random1_50;
a[8] = 55;
a[2] = 41 - a[0];
a[5] = 91;
a[4] = 28 - a[6];
a[1] = 66 - a[0] - a[5];
a[7] = 99 - a[3] - a[1];
}
public static void main(String[] args){

String[] str = new String[200];
for(int i = 0;i<200;i++){
new D_port_Calc_The_Customer_useAuthorizationCode();//为什么多次进行创建对象?难道会因为时间改变把初始化的东西也改变了?
for(int j = 0;j<9;j++){
str[i] = new String(a[j]);
                        System.out.println(str[i]);
}
}
}
}


------ For reference only ------------------------------------ ---
brother my above class file code is as follows :
package d_port_package;

public class D_port_Calc_The_Customer_useAuthorizationCode {
static int [] a = new int [50];
static char [] code = new char [9];
int random = 0;
static int random0_4 = 0;
static int random1_50 = 0;
static int random1_50jumb5 = 0;
public D_port_Calc_The_Customer_useAuthorizationCode () {
long time2 = System.currentTimeMillis ();
String dataformat = Long.toString (time2);
String Standarddataformat = dataformat.substring (12,13);
System.out.println (Standarddataformat);
random0_4 = Integer.parseInt (Standarddataformat) / 2;
random1_50jumb5 = Integer.parseInt (Standarddataformat +1) * 5/2;
random1_50 = Integer.parseInt (Standarddataformat)-random0_4;
a [0] = random1_50;
a [3] = random1_50;
a [6] = random1_50;
a [8] = 55;
a [2] = 41 - a [0];
a [5] = 91;
a [4] = 28 - a [6];
a [1] = 66 - a [0] - a [5];
a [7] = 99 - a [3] - a [1];
}
public static void main (String [] args) {

String [] str = new String [200];
for (int i = 0; i <200; i + +) {
new D_port_Calc_The_Customer_useAuthorizationCode ();

for (int j = 0; j <9; j + +) {
code [j] = (char) a [j];
}
str [i] = new String (code);
System.out.println (str [i]);
}
}
}

------ For reference only ---------------------------------- -----
package d_port_package;

public class D_port_Calc_The_Customer_useAuthorizationCode {
static int[] a = new int[50];
static char[] code = new char[9];
int random = 0;
static int random0_4 = 0;
static int random1_50 = 0;
static int random1_50jumb5 = 0; 
public D_port_Calc_The_Customer_useAuthorizationCode(){
long time2=System.currentTimeMillis(); 
String dataformat = Long.toString(time2);
String Standarddataformat = dataformat.substring(12,13);
System.out.println(Standarddataformat);
random0_4 = Integer.parseInt(Standarddataformat)/2;
random1_50jumb5 = Integer.parseInt(Standarddataformat+1)*5/2;
random1_50 = Integer.parseInt(Standarddataformat)-random0_4;
a[0] = random1_50;
a[3] = random1_50;
a[6] = random1_50;
a[8] = 55;
a[2] = 41 - a[0];
a[5] = 91;
a[4] = 28 - a[6];
a[1] = 66 - a[0] - a[5];
a[7] = 99 - a[3] - a[1];
}
public static void main(String[] args){

String[] str = new String[200];
for(int i = 0;i<200;i++){
new D_port_Calc_The_Customer_useAuthorizationCode();

for(int j = 0;j<9;j++){
code[j] = (char)a[j];
}
 str[i] = new String(code);
System.out.println(str[i]);
}
}
}

standard version format code above .
------ For reference only -------------------- -------------------
computer is running too quickly , each time for loop sleep 1ms try
------ For reference only ---------------------------------------
Here are some corrections

str[i] = ""+a[j];

Test Results:
6
3
-28
38
3
25
91
3
124
55
------ For reference only --------------------------------- ------
number to string conversion there are many ways , but can not use the mandatory conversion .
first: use api method inside
The second: with an empty string + digital form will automatically figure into
------ For reference only ----------------- ----------------------
fudongrifdr brother, thank you for your coaching ! !
brother I now get to the conclusion that :
as "Last night is your " brother of the message, where "toString () method " during "assignment when calculating " , is an address assigned to the other No left variable of type String ....
fudongrifdr brother , as " last night that you" help solve the many brother and the " God grant me FUTURE bar " Brother of the fee of effort ..
brother me, today owe you a credit ..
have another chance in the future , brother I'll make up your score !
Last night was your brother , God gave me FUTURE bar brother , thank you for their help solve the problem ! !
if given the opportunity , some in the " material world " who cultivated repay you ! !
in the wine ! !

没有评论:

发表评论