import java.util.ArrayList;
import java.util.List;
public class ScalbAll {
public static void main(String[] args) {
int result = 49;
List als = new ArrayList();
int n = 0;
while (true) {
double d = Math.scalb(2, n);
if (d > result) {
als.add(n + "");
result = result - (int) Math.scalb(2, n - 1);
n = 0;
} else {
n++;
}
if (result <= 0) {
break;
}
}
for (int i = als.size() - 1; i >= 0; i--) {
System.out.println(als.get(i));
}
}
}
楼上朋友的思路很有意思,我也实现了
List als = new ArrayList();
String str = Integer.toBinaryString(49);
int length = str.length();
for (int i = 0; i < length; i++) {
String tmp = str.substring(i, i + 1);
if ("1".equals(tmp)) {
als.add("" + (length - i - 1));
}
}
for (int i = als.size() - 1; i >= 0; i--) {
System.out.println(als.get(i));
}
我用的是JDK1.6.0_05可能是新加的方法吧,我这里是好用的
1
Rectangle::Rectangle(int top,int left,int bottom,int right)
{
itsTop=bottom;
itsLeft=right;
itsBottom=top;
itsRight=left;
}
2
//Rectangle.h
#ifndef _CODE1_1_H_INCLUDE_
#define _CODE1_1_H_INCLUDE_
class Rectangle
{
...........
};
#endif
//Rectangle.cpp
#include"Rectangle.h"
point类类似_CODE1_1_H_INCLUDE_
这个值改一下
3
没什么必要的
void SetBottom(const int bottom)
void SetRight(const int right)
4
class Rectangle
{
public:
Rectangle(int top,int left,int bottom,int right);
~Rectangle(){}
int GetTop()const
int GetLeft()const
int GetBottom()const
int GetRight()const
void SetTop(int top)
void SetLeft(int left)
void SetBottom(int bottom)
void SetRight(int right)
int GetArea( )const;
private:
int itsTop;
int itsLeft;
int itsBottom;
int itsRight;
static double a;
};
int Rectangle::a=0;
在构造函数里面
Rectangle::Rectangle(int top,int left,int bottom,int right)
{
itsTop=bottom;
itsLeft=right;
itsBottom=top;
itsRight=left;
a+=GetArea();
}
我做过RSA的加解密算法和数字签名算法。
QQ:420371649
bensetang@126.com
毕业设计啊,可以联系我试,咱们再谈嘛
如果你能给劳务费很乐意帮你,我就是计算机专业的!QQ:980515024
怎么说呢,就算很简单也是要钱的.要么你去找自己的朋友