Input a decimal number from the keyboard and output its binary number

The code is as follows:

/*Input a decimal number from the keyboard and output its binary number * / import Java util. Scanner; Class demo17 {public static void main (string [] args) {scanner SC = new scanner (system. In); system. Out. Println ("please enter a positive decimal integer:"); int num = sc.nextint(); int Shang = num; int r = 0; string res = ""; / / save the remainder while (Shang! = 0) {r = Shang% 2; res = R + res; / / put the remainder just found in front of Shang = Shang / 2;} System. out. Println (binary form of num + "is:" + RES);}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>