谁对JAVA熟悉,能否把这段代码改成JAVA的呢?:)(80分)

  • 主题发起人 主题发起人 liuyang
  • 开始时间 开始时间
L

liuyang

Unregistered / Unconfirmed
GUEST, unregistred user!
function dwdmjym(dwdm:string;var ReChar:Char):Boolean;<br>const<br> Wi: array[1..8] of string = ('3','7','9','10','5','8','4','2');<br> ai: array[0..35] of string = ('0','1','2','3','4','5','6','7','8','9','A',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'B','C','D','E','F','G','H','I','J','K','L',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'M','N','O','P','Q','R','S','T','U','V','W',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'X','Y','Z');<br> bi: array[0..35] of string = ('0','1','2','3','4','5','6','7','8','9','10',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '11','12','13','14','15','16','17','18','19','20','21',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '22','23','24','25','26','27','28','29','30','31','32',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '33','34','35');<br> &nbsp; function GetAi(S:Char):string;<br> &nbsp; var I:integer;<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp;Result :='';<br> &nbsp; &nbsp; &nbsp;for I:=0 to 35 do<br> &nbsp; &nbsp; &nbsp; &nbsp; if S=ai then<br> &nbsp; &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result :=bi;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Break;<br> &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; end;<br>var<br> &nbsp; J,Sum,ModResult:integer;<br> &nbsp; S:string;<br>begin<br> &nbsp; Result:=True;<br> &nbsp; Sum:=0;<br> &nbsp; for J:=1 to Length(dwdm) do<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; S:=GetAi(dwdm[J]);<br> &nbsp; &nbsp; &nbsp; &nbsp; if S='' then<br> &nbsp; &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result :=False;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Break;<br> &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp; &nbsp; Sum:=Sum+strtoint(S)*strtoint(Wi[J]);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; if not Result then Exit;<br> &nbsp; ModResult:=Sum mod 11;<br> &nbsp; if ModResult=1 then ReChar:='X'<br> &nbsp; else if ModResult=0 then ReChar:='0'<br> &nbsp; else begin<br> &nbsp; &nbsp; &nbsp;S :=inttostr(11-ModResult);<br> &nbsp; &nbsp; &nbsp;ReChar:=S[1];<br> &nbsp; end;<br>end;<br><br>function dwdmjy(dwdm:string):Boolean;<br>var ReChar:Char;<br>begin<br> &nbsp; Result :=dwdmjym(Copy(dwdm,1,8),ReChar);<br> &nbsp; if Result then<br> &nbsp; &nbsp; &nbsp;if ReChar&lt;&gt;dwdm[9] then Result :=False;<br>end;
 
不知道对不对,依胡芦画瓢<br>package JavaTest;<br><br>public class DelphiToJava {<br> static String[] wi = {&quot;3&quot;,&quot;7&quot;,&quot;9&quot;,&quot;10&quot;,&quot;5&quot;,&quot;8&quot;,&quot;4&quot;,&quot;2&quot;};<br> static char[] ai = {'0','1','2','3','4','5','6','7','8','9','A',<br> &nbsp; &nbsp; &nbsp; 'B','C','D','E','F','G','H','I','J','K','L', <br> &nbsp; &nbsp; &nbsp; 'M','N','O','P','Q','R','S','T','U','V','W',<br> &nbsp; &nbsp; &nbsp; 'X','Y','Z'};<br> static String[] bi = {&quot;0&quot;,&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;11&quot;,&quot;12&quot;,&quot;13&quot;,&quot;14&quot;,&quot;15&quot;,&quot;16&quot;,&quot;17&quot;,&quot;18&quot;,&quot;19&quot;,&quot;20&quot;,&quot;21&quot;,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;22&quot;,&quot;23&quot;,&quot;24&quot;,&quot;25&quot;,&quot;26&quot;,&quot;27&quot;,&quot;28&quot;,&quot;29&quot;,&quot;30&quot;,&quot;31&quot;,&quot;32&quot;,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;33&quot;,&quot;34&quot;,&quot;35&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };<br> <br> &nbsp; &nbsp;public static String getAi(char s){<br> &nbsp; &nbsp; <br> &nbsp; &nbsp; for(int i = 0; i &lt; 35; i++){<br> &nbsp; &nbsp; if (ai == s){<br> &nbsp; &nbsp; return bi;<br> &nbsp; &nbsp; }};<br> &nbsp; &nbsp; return &quot;&quot;;<br> &nbsp; &nbsp;}<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;public static boolean dwdmjym(String dwdm, char[] rechar){<br> &nbsp; &nbsp; int ModResult;<br> &nbsp; &nbsp; int sum = 0;<br> &nbsp; &nbsp; String s, h;<br> &nbsp; &nbsp; for(int j = 0; j &lt; dwdm.length() - 1; j++){<br> &nbsp; &nbsp; s = getAi(dwdm.charAt(j));<br> &nbsp; &nbsp; if (s.equals(&quot;&quot;)){<br> &nbsp; &nbsp; return false;<br> &nbsp; &nbsp; }<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; {<br> &nbsp; &nbsp; sum += Integer.parseInt(s) * Integer.parseInt(wi[j]); <br> &nbsp; &nbsp; }<br> &nbsp; &nbsp; }<br> &nbsp; &nbsp; ModResult = sum % 11;<br> &nbsp; &nbsp; switch(ModResult){<br> &nbsp; &nbsp; &nbsp;case 1: rechar[0] = 'X'; break;<br> &nbsp; &nbsp; &nbsp;case 0: rechar[0] = '0'; break;<br> &nbsp; &nbsp; &nbsp;default:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;h = String.valueOf(11 - ModResult);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rechar[0] = h.charAt(0);<br> &nbsp; &nbsp; }<br> &nbsp; &nbsp; <br> &nbsp; &nbsp; return true;<br> &nbsp; &nbsp;}<br><br> &nbsp; &nbsp;public static boolean dwdmjy(String dwdm){<br> &nbsp; &nbsp; char[] rechar = new char[1];<br> &nbsp; &nbsp; boolean rs;<br> &nbsp; &nbsp; String tempdwdm = &quot;&quot;;<br> &nbsp; &nbsp; for(int i = 0; i &lt; 8; i++){<br> &nbsp; &nbsp; tempdwdm += dwdm.charAt(i);<br> &nbsp; &nbsp; }<br> &nbsp; &nbsp; rs = dwdmjym(tempdwdm, rechar);<br> &nbsp; &nbsp; if(rs){<br> &nbsp; &nbsp; if (rechar[0] != dwdm.charAt(8))<br> &nbsp; &nbsp; &nbsp;return false;<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp;return true; <br> &nbsp; &nbsp; }<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; return false;<br> &nbsp; &nbsp; <br> &nbsp; &nbsp; <br> &nbsp; &nbsp;}<br><br><br> /**<br> * @param args<br> */<br> public static void main(String[] args) {<br> // TODO Auto-generated method stub<br> if(dwdmjy(&quot;254444588&quot;)){<br> System.out.print(true);<br> }<br> else<br> System.out.print(false);<br> }<br><br>}
 
强,我下午看看,一定给分!多谢这位大侠:)
 
接受答案了.
 
后退
顶部