命令行输入,这样写一下
Scanner sc = new Scanner(System.in);
long m = sc.nextLong();
包:
java.util.Scanner
简单地
import java.util.Scanner;
class DigitCounter{
public static void main(String args[]) throws Exception{
System.out.println("请输入十六位长整型数m: ");
Scanner sc = new Scanner(System.in);
long m = sc.nextLong();
String str = String.valueOf(m);
int counter[]=new int[10];
for(int i=0;i
int p = ((byte)str.charAt(i))-0x30;
switch(p){
case 0:
counter[0]++;
break;
case 1:
counter[1]++;
break;
case 2:
counter[2]++;
break;
case 3:
counter[3]++;
break;
case 4:
counter[4]++;
break;
case 5:
counter[5]++;
break;
case 6:
counter[6]++;
break;
case 7:
counter[7]++;
break;
case 8:
counter[8]++;
break;
default:
counter[9]++;
}
}
for(int i=0; i<10; i++){
System.out.println( String.format("%d出现的次数%d", i, counter[i] ) );
}
}
}
p=m/(Math.pow(10,i)); 这行是有问题的。。。p是一个int类型的,m/(Math.pow(10,i))结果是一个double类型的。。。