【发布时间】:2016-01-14 18:37:57
【问题描述】:
我正在做作业,以为我已经完成了,但老师告诉我这不是他想要的,所以我需要知道如何将存储为字符串的二进制数转换为十进制数字符串,不使用 Java 中的 length()、charAt()、power 函数和 floor/ceiling 之外的任何内置函数。
这就是我一开始的样子。
import java.util.Scanner;
public class inclass2Fall15Second {
public static void convertBinaryToDecimalString() {
Scanner myscnr = new Scanner(System.in);
int decimal = 0;
String binary;
System.out.println("Please enter a binary number: ");
binary = myscnr.nextLine();
decimal = Integer.parseInt(binary, 2);
System.out.println("The decimal number that corresponds to " + binary + " is " + decimal);
}
public static void main (String[] args) {
convertBinaryToDecimalString();
}
}
【问题讨论】:
-
向我们展示您已经尝试过的内容。没有任何代码,我们无法为您提供帮助。
-
您编码的语言是什么?如果没有这些信息,我们将无法为您提供帮助。
-
我用这些信息更新了我的帖子。我很抱歉没有具体说明。
-
@BDM 检查我的更新解决方案
标签: java binary type-conversion decimal data-conversion