为了账号安全,请及时绑定邮箱和手机立即绑定

我正在开发一个十六进制到十进制转换器

我正在开发一个十六进制到十进制转换器

红颜莎娜 2023-10-12 17:12:06
我的程序的输出应该在文本变量中,但它不起作用。请帮帮我,这是学校比赛。当我给它 ex.:AE2362 时,它只是不打印任何内容(我之前向它声明的值)。import java.util.Scanner;public class Main {    public static void main(String[] args) {        String[] g =  new String[6];        String abc = "ABCDEF";        for(int  i =0; i<= g.length-1;i++) {                char c = abc.charAt(i);                g[i] =  String.valueOf(c);        }        Scanner sc =  new Scanner(System.in);        System.out.println("Enter a hexadecimal code:");        String inp = sc.nextLine();        sc.close();        String text ="";        for(int i =0;i<=inp.length()-1;i++) {            char c2 = inp.charAt(i);            for(int h =0;h<=g.length-1;h++) {                   if(String.valueOf(c2)==g[h]) {                    text += String.valueOf(h+10);                }            }            if(Integer.valueOf(c2)>=0&&Integer.valueOf(c2)<=9) {                text += String.valueOf(c2);            }           }        System.out.println(text);    }}
查看完整描述

1 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

果事实上它已经开发出来,你就不必发明它。

String hexValue = "put your hex in quotes";
int decimalValue = Integer.parseInt(hexValue, 16);

希望它会有所帮助


查看完整回答
反对 回复 2023-10-12
  • 1 回答
  • 0 关注
  • 54 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信