日期:2014-05-20  浏览次数:20818 次

新人处女帖:16进制转10进制问题,高手请进。
描述:屏幕上输入一个16进制数,输出一个10进制数。

1:
import java.util.Scanner;

public class test2 

public static void main(String[] args) 

Scanner scanner=new Scanner(System.in);
System.out.printf("请输入16进制数字:");
String s = scanner.next();
String c= Integer.valueOf("s",16).toString();
System.out.println(String.valueOf(c)); 


}

2:
import java.util.Scanner;

public class test2 

public static void main(String[] args) 

Scanner scanner=new Scanner(System.in);
System.out.printf("请输入16进制数字:");
String s = scanner.next();
int d =Integer.parseInt(s);
System.out.println(Integer.toString(d));


}

1,2都不正确。请高手帮忙。

------解决方案--------------------
第一个写错了,“s”改称s
------解决方案--------------------
Java code

import java.util.Scanner;


public class Test {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in); 
        System.out.println("请输入16进制数字:"); 
        String s = scanner.next(); 
        System.out.println(Integer.parseInt(s,16));   
    }
}

------解决方案--------------------
1
Java code
import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.printf("请输入16进制数字:");
        String s = scanner.next();
        String c = Integer.valueOf(s, 16).toString();
        System.out.println(String.valueOf(c));

    }
}

------解决方案--------------------

import java.util.Scanner;

public class Test {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.printf("请输入16进制数字:");
String s = scanner.next();
String c = Integer.valueOf(s, 16).toString();
System.out.println(String.valueOf(c));

}
}
------解决方案--------------------
探讨

import java.util.Scanner;

public class Test {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.printf("请输入16进制数字:");
String s = scanner.next();
String c = Integer.valueOf(s, 16).toString();
System.out.println(String.valueOf(c));

}
}