从键盘输入某个十进制整数,转换成对应的二进制整数并输出。

package pro;

import java.util.Scanner;

/**

 * 从键盘输入某个十进制整数,转换成对应的二进制整数并输出。

 *

 * @author 常朋辉

 */

public class Homework {

       public static void main(String[] args) {

              package pro;

 

import java.util.Scanner;

 

public class Home81 {

       public static void main(String[] args) {

              Scanner stc = new Scanner(System.in);

              System.out.println("请输入一个十进制的整数:");

              int num = stc.nextInt();

              int c = 0, d = 1;

              int n;

              for (int i = 1;; i++) {

                     n = num % 2;

                     num = num / 2;

                     c = c + n * d;

                     d = d * 10;

                     if (num == 0) {

                            break;

                     }

              }

              System.out.print(c);

       }

你可能感兴趣的:(程序)