我是靠谱客的博主 殷勤斑马,这篇文章主要介绍从键盘输入一个十进制整数数,转换成对应的二进制整数并输出。,现在分享给大家,希望可以做个参考。

import java.util.Scanner;
/*
 *@author Julain 
 *reminder 余数
 * quotient 商
 */
public class Convertion {
	public static void main(String[] args) {
		System.out.println("请输入一个十进制数");
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int quotient = input / 2;
		int reminder = input - quotient * 2;
		String result = "";
		result = reminder + result;
		while (quotient >= 2) {
			int tmp = quotient / 2;
			reminder = quotient - tmp * 2;
			result = reminder + result;
			quotient = tmp;
		}
		result = quotient + result;
		System.out.println("转换成二进制结果为:");
		System.out.println(result);
		sc.close();
	}
}

**编写环境JDK、JRE、Eclipse、

最后

以上就是殷勤斑马最近收集整理的关于从键盘输入一个十进制整数数,转换成对应的二进制整数并输出。的全部内容,更多相关从键盘输入一个十进制整数数,转换成对应内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部