描述:屏幕上输入一个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));
}
}
------解决方案--------------------