PS: This problem just finished, full marks, can refer
/* Title: Digital string to binary binary
* Description: Enter a string of integers, convert each integer to binary number, if the third bit is "0", then output "0", if "1", then output "1".
Topic Category: Bit arithmetic
Difficulty: Beginner
Score: 60
Operating time limit: Ten Sec
Memory Limit: MByte
Stage: Application for examination
Input: A string of integers with a length of less than 1024 and integers separated by spaces
Output: 1/0 integer string, separated by spaces
Sample input: 240 0
Sample output: 0 0
Answer hint:
*/
1 ImportJava.util.Scanner;2 3 Public classMain {4 5 Public Static voidMain (string[] args) {6 7String bitstr = "";8 9Scanner cin =NewScanner (system.in);TenString str =cin.nextline (); One ABitstr =getbitstring (str); - - System.out.println (BITSTR); the cin.close (); - - } - + Private Staticstring getbitstring (String str) { - + intLen = 0; A intbit = 0; at intnum = 0; -StringBuilder SB =NewStringBuilder (); - -string[] Strarray = Str.split (""); -Len =strarray.length; - in if(Len >= 1024) - { to return""; + } - the for(inti = 0; i < Len; i++) * { $num =Integer.parseint (Strarray[i]);Panax NotoginsengNum/= 4; -bit = num% 2; the +Sb.append (bit+ ""); A } the + returnSb.tostring (). substring (0, Sb.length ()-1); - } $ $}
Huawei on-Machine test problem (digital string to binary-java)