问题:
之前做过类似题,但这次仍然不能解决相关问题。
字符串倒过来输:StringBuffer str=new StringBuffer(s); s=str.reverse().toString()
Bitset
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15548 Accepted Submission(s): 11804
Problem Description
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Input
For each case there is a postive number n on base ten, end of file.
Output
For each case output a number on base two.
Sample Input
1
2
3
Sample Output
1
10
11
代码:
import java.util.*; public class Main{
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
int n=cin.nextInt();
String s="";
while(n!=0){
s=s+(n%2);
n=n/2;
}
StringBuffer str=new StringBuffer(s);
s=str.reverse().toString();
System.out.println(str);
}
}
}