62,614
社区成员
发帖
与我相关
我的任务
分享
String number;
long num,numLength;
long n = 0,count = 0,m;
number = JOptionPane.showInputDialog("Enter numbers");
num = Long.parseLong(number);
numLength = number.length();
while(n<numLength){
m = (long) (num/Math.pow(10, n)%10*Math.pow(2, n));
count = count + m;
n++;
}
JOptionPane.showMessageDialog(null, count,"",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
String number;
int num;
int count = 0;
number = JOptionPane.showInputDialog("Enter numbers");
num = Integer.parseInt(number);
int j = String.valueOf(num).length();
while(i > 0) {
int n = num / (int)(Math.pow(10,j - 1));
count = n *(int)(Math.pow(2,j-1)) + count;
num = num - (int)(Math.pow(10,j - 1));
j--;
}
JOptionPane.showMessageDialog(null, count,"",JOptionPane.INFORMATION_MESSAGE);